【发布时间】:2012-11-19 05:30:02
【问题描述】:
我正在将我的应用程序转换为 ios6,但我遇到了旋转问题。 谁能帮我旋转设备时会调用哪些方法
【问题讨论】:
标签: ios6 screen-rotation
我正在将我的应用程序转换为 ios6,但我遇到了旋转问题。 谁能帮我旋转设备时会调用哪些方法
【问题讨论】:
标签: ios6 screen-rotation
- (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
}
}
这些是 ios 6 中的新方法,您可以在其中根据方向设置框架。希望对你有用。
【讨论】:
- (BOOL) shouldAutorotate
-(NSUInteger)supportedInterfaceOrientations
这些是 iOS 6 中添加的新功能。
【讨论】:
-(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
}
}
最好用这个,每次你改变设备的方向时,上面的方法都会调用。
【讨论】:
使用这些方法处理旋转
-(BOOL) shouldAutorotate
{
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
如果某些视图在旋转并且您不希望 UIImagePickerController 之类的,只需创建一个子类并覆盖第一个方法。
【讨论】: