Ios 如何在UIDeviceOrientationSportRait中设置iPhone应用程序的方向?
我正在开发一个IOS应用程序,我使用以下代码锁定应用程序的Ios 如何在UIDeviceOrientationSportRait中设置iPhone应用程序的方向?,ios,iphone,orientation,Ios,Iphone,Orientation,我正在开发一个IOS应用程序,我使用以下代码锁定应用程序的方向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)shouldAutorotate { return NO; } - (NSUI
方向
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
启动应用程序时,如果方向
为ui界面方向纵向
。它会将方向
锁定到ui界面方向纵向
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated] ;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//set the orientation is Portrait when the App start.
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait );
}
}
但是当在横向
中启动应用程序时,视图仍然显示横向
如何将应用程序的方向设置为UIDeviceOrientationIsPortrait
以启动应用程序无论手机是横向
还是“纵向”?
如果需要将整个应用程序锁定为纵向,请转到目标->常规选项卡->部署信息
这会将整个应用程序锁定为纵向模式如果整个应用程序只需要一个方向,则转到目标、常规和部署信息。然后检查纵向。我使用以下代码将方向设置为纵向
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated] ;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//set the orientation is Portrait when the App start.
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait );
}
}