關於iOS6.0 屏幕旋轉的問題 – iPhone手機開發技術文章 iPhone軟體開發教學課程

1、首先在appDelegate中,把view添加到window中有兩種方式、

[cpp]
self.window.rootViewController = self.view; 
[self.window addSubview:self.view.view]; 

    self.window.rootViewController = self.view;
    [self.window addSubview:self.view.view];
但是如果用第二種的話,在ios6.0中 再去設置屏幕旋轉是沒有任何效果的,必須使用第一種。在ios6.0以前的版本是沒有這種分別的。

2、 開啟全部方向屏幕旋轉的方式

iOS6.0之前: 隻需這個方法返回yes即可

[cpp] www.aiwalls.com
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 

    return YES; 

    – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
     return YES;
    }   iOS6.0中  需要這三個方法一起使用才可以

[cpp]
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 

    return (toInterfaceOrientation != UIInterfaceOrientationMaskPortraitUpsideDown); 

– (BOOL)shouldAutorotate 

    return YES; 

– (NSUInteger)supportedInterfaceOrientations 

    return UIInterfaceOrientationMaskAllButUpsideDown; 

    – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
     return (toInterfaceOrientation != UIInterfaceOrientationMaskPortraitUpsideDown);
    }
    – (BOOL)shouldAutorotate
    {
     return YES;
    }
    – (NSUInteger)supportedInterfaceOrientations
    {
     return UIInterfaceOrientationMaskAllButUpsideDown;
    }當然瞭關閉全部方向屏幕旋轉的方式則把上面的返回值改為no即可

iOS6.0之前:

[cpp]
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 

    return NO; 

    – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
     return NO;
    }   iOS6.0中

[cpp]
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 

return (toInterfaceOrientation == UIInterfaceOrientationPortrait); 

– (BOOL)shouldAutorotate 

return NO; 

– (NSUInteger)supportedInterfaceOrientations 

    return UIInterfaceOrientationMaskPortrait;//隻支持這一個方向(正常的方向)  

    – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
    }
    – (BOOL)shouldAutorotate
    {
    return NO;
    }
    – (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;//隻支持這一個方向(正常的方向)
    }

使用屏幕旋轉常用的方法

[cpp]
//視圖旋轉之前自動調用  
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    NSLog(@"視圖旋轉之前自動調用"); 

//視圖旋轉方向發生改變時會自動調用  
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

    NSLog(@"視圖旋轉方向發生改變時會自動調用"); 

//視圖旋轉完成之後會自動調用  
 
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    NSLog(@"視圖旋轉完成之後自動調用"); 

//視圖旋轉之前自動調用
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    NSLog(@"視圖旋轉之前自動調用");
}
//視圖旋轉方向發生改變時會自動調用
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"視圖旋轉方向發生改變時會自動調用");
}
//視圖旋轉完成之後會自動調用

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    NSLog(@"視圖旋轉完成之後自動調用");
}

 

發佈留言