CS185c
Chris Pollett
Sep. 21, 2009
To make the keyboard go away after a user hits return on the iPhone, the programmer needs to:
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
-(void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:
(UIInterfaceOrientation)fromInterfaceOrientation
duration:(NSTimeInterval)duration {
UIInterfaceOrientation toOrientation = self.interfaceOrientation;
[UIView beginAnimations:@"move my stuff" context:nil];
//says we'd like the switch animated; give animation block a name
if(toOrientation == UIInterfaceOrientationPortrait ||
toOrientation == UIInterfaceOrientationPortraitUpsideDown) {
myScreenComponent.frame = CGRectMake(x,y,width, height);
// ...
} else {
myScreenComponent.frame = CGRectMake(xlandscape,ylandscape, width_ls, height_ls);
// ...
}
[UIView commitAnimations];
// our animation clock is finished
}
IBOutlet UIView *landscape; IBOutlet UIView *portrait;
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;
// degreesToRadian is #define degreesToRadian(x) (M_PI *(x)/180.0)
NSLog(@"Hello world of logging");