2015-09-19 56 views
-1

我想我的UIWebView被鎖定在肖像模式,直到進度視圖完成加載,然後讓它支持所有的方向..這可能嗎?這裏我試圖使用的代碼:如何更改viewController支持的方向?

class MyWebViewController: UIViewController, UIWebViewDelegate { 

@IBOutlet var myWebView: UIWebView! 

@IBOutlet var progressView: UIProgressView! 

var contentUrlPassedOn: String! 

override func viewDidLoad() { 
     super.viewDidLoad() 

    myWebView.delegate = self 
    let url: NSURL! = NSURL(string: contentUrlPassedOn) 
    myWebView.loadRequest(NSURLRequest(URL: url)) 
} 
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 

    return [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.PortraitUpsideDown] 
} 

func updateProgress(){ 

    self.activityIndicator.startAnimating() 

    if progressView.progress >= 1 { 

    UIInterfaceOrientationMask.All 

} else { 
    //... 
} 

這是不成功的..任何建議,我怎麼能做到這一點?

回答

0
override func shouldAutorotate() -> Bool { 
if (UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft || 
    UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight || 
    UIDevice.currentDevice().orientation == UIDeviceOrientation.Unknown) { 
     return false; 
} 
else { 
    return true; 
} 

override func supportedInterfaceOrientations() -> Int { 
return Int(UIInterfaceOrientationMask.Portrait.rawValue) | Int(UIInterfaceOrientationMask.PortraitUpsideDown.rawValue) 
} 

複製並粘貼到您在肖像模式下只想要

希望這有助於在VC上面的代碼! 最好的運氣, SUPREM

+0

這不是眼前的問題,我想它在縱向模式下,直到進度完成加載.. –

0

offcource我們可以控制好方向,用布爾值一樣isWebViewLoaded

- (void)webViewDidStartLoad:(UIWebView *)webView 
{ 

    self.isWebViewLoaded = NO; 
} 

-(void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    self.isWebViewLoaded = YES; 
} 

並檢查定位法的條件......如果self.isWebViewLoaded = YES然後讓所有的取向else限制只肖像模式,最後復位布爾值按照您的要求....

試試這個方法....

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    if (self.isLoad == NO) 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    else 
     return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 
+0

所以你能在你的代碼包括方位的限制,除了與肖像'isWebViewLoaded = NO'和的addidtion所有的方向都是'isWebViewLoaded = YES' –