2015-09-19 58 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' –