簡體   English   中英

如何在iOS 6及更高版本中將單個視圖從縱向旋轉為橫向?

[英]How to rotate a single view from portrait to landscape in iOS 6 and above?

我無法將單個屏幕從縱向旋轉到橫向。 因此,如果我想這樣做,那么我必須將整個應用程序修改為縱向和橫向模式嗎?

不,您不需要修改整個應用程序。

有一些委托方法可以用來實現。 如果您的應用程序具有標簽欄或導航欄, 請參閱我的問題 我會幫你的。

如果要在橫向模式下旋轉屏幕,請使用此方法

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

 {

return UIInterfaceOrientationIsLandscape(interfaceOrientation);

}

如果要全方位旋轉,則返回YES;否則,返回YES。

我也發現了同樣的問題。我發現應該每次都不應該調用shouldAutorotate函數,所以我以編程方式更改方向

首先導入這個

#import <objc/message.h>

然后

-(void)viewDidAppear:(BOOL)animated
{

     if(UIDeviceOrientationIsPortrait(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft );


        }
    }

}

希望對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM