Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UIDeviceOrientationSportRait中设置iPhone应用程序的方向?_Ios_Iphone_Orientation - Fatal编程技术网

Ios 如何在UIDeviceOrientationSportRait中设置iPhone应用程序的方向?

Ios 如何在UIDeviceOrientationSportRait中设置iPhone应用程序的方向?,ios,iphone,orientation,Ios,Iphone,Orientation,我正在开发一个IOS应用程序,我使用以下代码锁定应用程序的方向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)shouldAutorotate { return NO; } - (NSUI

我正在开发一个IOS应用程序,我使用以下代码锁定应用程序的
方向

- (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 );
    }
}