CS185c
Chris Pollett
Feb. 27, 2012
#import <UIKit/UIKit.h> @interface SecondPhone2012ViewController : UIViewController @property (weak, nonatomic) IBOutlet UIButton *button1; @property (weak, nonatomic) IBOutlet UIButton *button2; @property (weak, nonatomic) IBOutlet UIButton *button3; @property (weak, nonatomic) IBOutlet UIButton *button4; @property (weak, nonatomic) IBOutlet UIButton *button5; @property (weak, nonatomic) IBOutlet UIButton *button6; @end
@synthesize button1;
@synthesize button2;
@synthesize button3;
@synthesize button4;
@synthesize button5;
@synthesize button6;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self willAnimateRotationToInterfaceOrientation: self.interfaceOrientation duration:0];
}
-(void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
duration:(NSTimeInterval)duration {
if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
button1.frame = CGRectMake(20, 20, 125, 125);
button2.frame = CGRectMake(175, 20, 125, 125);
button3.frame = CGRectMake(20, 168, 125, 125);
button4.frame = CGRectMake(175, 168, 125, 125);
button5.frame = CGRectMake(20, 315, 125, 125);
button6.frame = CGRectMake(175, 315, 125, 125);
} else {
button1.frame = CGRectMake(20, 20, 125, 125);
button2.frame = CGRectMake(20, 155, 125, 125);
button3.frame = CGRectMake(177, 20, 125, 125);
button4.frame = CGRectMake(177, 155, 125, 125);
button5.frame = CGRectMake(328, 20, 125, 125);
button6.frame = CGRectMake(328, 155, 125, 125);
}
}
//note strong as the controller DOES own them @property (strong, nonatomic) IBOutlet UIView *portrait; @property (strong, nonatomic) IBOutlet UIView *landscape;
#define degreesToRadians(x) (M_PI * (x)/180.0)
if(toOrientation == UIInterfaceOrientationPortrait)
{
self.view = self.portrait; //selects which view
//next two lines set up rotation need
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
// this is rect view should live in
self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0);
}
else if (toOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
self.view.bounds = CGRectMake(0.0, 0.0, 460, 320);
}
// similar code for the other two orientations;
Which of the following is true?
NSLog(@"Hello world of logging");
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
setContentView(R.layout.main_portrait);
}
else
{
setContentView(R.layout.main_landscape);
}
//other code of onCreate
}
Log.i("Hw1", "Main ViewCreated");
SharedPreferences myPref = getSharedPreferences("MY_APP_PREFS",
Context.MODE_WORLD_WRITEABLE + Context.MODE_WORLD_READABLE);
Log.i("My_Activity",
"Old Some_Key" + myPref.getString("Some_Key","Key did not exist") );
//second arg is returned if key did not exist
Editor myPrefEditor = myPref.edit();
myPrefEditor.putString("Some_Key", "Some Value");
myPrefEditor.commit();