问题
I am converting my app to ios6 but i am getting rotation problems. Can some one help me which methods will be called when we rotate device
回答1:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self doLayoutForOrientation:toInterfaceOrientation];
}
- (void)doLayoutForOrientation:(UIInterfaceOrientation)orientation {
if (UIInterfaceOrientationIsPortrait(orientation))
{
//set the frames here
}
else
{
//set the frames here
}
}
These are the new methods in ios 6 where you can set the frames as per the orientation. Hope it will useful to you.
回答2:
- (BOOL) shouldAutorotate
-(NSUInteger)supportedInterfaceOrientations
These are the new functions added to iOS 6.
回答3:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
-(void)viewWillLayoutSubviews
{
if([self interfaceOrientation] == UIInterfaceOrientationPortrait||[self interfaceOrientation] ==UIInterfaceOrientationPortraitUpsideDown)
{
//set the frames here
}
else if ([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft||[self interfaceOrientation] == UIInterfaceOrientationLandscapeRight)
{
//set the frames here
}
}
better go with this , the above method will call every time when you change the orientation of the device.
回答4:
Handle the rotation with these methods
-(BOOL) shouldAutorotate
{
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
If some-view in rotating and you don't want such as UIImagePickerController just make a child class and override first method.
来源:https://stackoverflow.com/questions/13448192/ios6-rotation-problems