[英]App support the app Landscape and portrait mode in both ipad and iphone
[英]How to design an iOS app which runs only in landscape mode in ipad and portrait in iPhone?
我是iOS开发的新手,正在开发可在iPad和iPhone上运行的应用程序,正在使用通用情节提要,我希望手机仅在纵向模式下工作,而iPad仅在横向模式下工作。风景中的ipad?我们可以旋转情节提要和设计吗?另外,让我知道如何锁定iPad的界面方向锁定。谢谢您。我需要Objective-C代码。
如图所示,在Info.Plist文件中添加两行。
Target--->General--->Deployment info.
在这种情况下,您需要创建两个不同的故事板。 一个用于iphone,一个用于ipad。
要以横向/纵向设计,您需要设置以下设置。
首先转到情节提要。 选择viewController->属性检查器->模拟度量->方向->更改为横向/纵向。
在“目标”中,将“设备方向”设置为iPad的“横向左”和“横向”,将iphone设置为“纵向”。
还告诉我您在情节提要中使用导航控制器吗???
如果您觉得有用,请投票。
您可以为视图控制器创建一个子类,在其中您可以在下面覆盖此方法。 这将启用iPad的横向和iPhone的纵向。
我使用在子类内部实现的此方法创建UIViewController的子类,然后在整个项目中将MySubclassViewController子类化。
// iOS6+
// MySubclassViewController.m
@interface MySubclassViewController : UIViewController
@end
/* Doc:
This method is only called if the view controller's
shouldAutorotate method returns YES.
*/
-(NSUInteger)supportedInterfaceOrientations{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
/* iPad device */
return UIInterfaceOrientationMaskLandscape;
}else{
/* iPhone device */
return UIInterfaceOrientationMaskPortrait;
}
}
- (BOOL)shouldAutorotate {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
}
return NO;
}
将其放在您的视图控制器中,相应地安排返回类型,我现在无法访问我的旧代码。
-(BOOL)isPad
{
#ifdef UI_USER_INTERFACE_IDIOM
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
#endif
return NO;
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
if([self isPad]){
return UIInterfaceOrientationMaskLandscape;
}
else{
return SOMETHING_ELSE;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if([self isPad]){
return return UIInterfaceOrientationLandscapeRight;
}
else{
return SOMETHING_ELSE;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.