我正在创建一个应用程序,它既可以是纵向也可以是横向模式。对于iOS 5.0
,我按照以下方式添加视图,即
-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight)))
{
productname.frame=CGRectMake(240, 97, 106, 20);
self.view = landscapeView;
}
else if
(((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){
productname.frame=CGRectMake(153, 151, 106, 20);
self.view = portraitView;
}
return YES;
}
但对于iOS 6.0
,我有两种方法,
我实际上需要一种必须在设备旋转期间触发的方法。如果有人有想法,请告诉我。我已经浪费了很多时间。
提前多多感谢。
答案 0 :(得分:1)
我正在使用UINavigationController子类,代码如下:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (self.topViewController.presentedViewController) {
return self.topViewController.presentedViewController.supportedInterfaceOrientations;
}
return self.topViewController.supportedInterfaceOrientations;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return self.topViewController.preferredInterfaceOrientationForPresentation;
}
这对我来说非常适合
并在AppDelegate.m文件中:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return [UIDevice isIpad] ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskAllButUpsideDown;
}
答案 1 :(得分:0)
使用
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration