2013-02-12 43 views
1

我使用下面的非常基本的代碼,我想學習如何做轉換適合初學者基本橫向旋轉CATransform3DMakeRotation似乎只用來工作

我想要做的長的第二次的方式來學習不僅僅是在「shouldautorotate」扔東西更多,這是我工作過的現在

- (void)viewDidLoad 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
} 


- (void)didRotate:(NSNotification *)notification 
{ 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    if (orientation == UIDeviceOrientationLandscapeRight) 
    { 
     [UIView animateWithDuration:0.2f animations:^{ 
      self.view.layer.transform = CATransform3DMakeRotation(-M_PI/2, 0, 0.0, 1.0); 
      [self.scrollViewImages setContentSize:CGSizeMake(self.view.frame.size.width*self.images.count, 320.0)]; 
      [self.scrollViewImages setContentOffset:CGPointMake(0, 0) animated:YES]; 
     } completion:^(BOOL finished) { 

     }]; 
    } else if(orientation == UIDeviceOrientationPortrait) { 
     [UIView animateWithDuration:0.2f animations:^{ 
      self.view.frame = CGRectMake(0, 0, 320.0, 480.0); 
      self.view.center = CGPointMake(160.0, 240.0); 
      self.view.transform = CGAffineTransformIdentity;    
     } completion:^(BOOL finished) { 

     }]; 
    } 
} 

代碼但是我第一次從縱向旋轉,我得到這個

portrait landscape

但一旦我把它恢復到肖像和旋轉,我再次receieve little more correct

我真的很抱歉,如果這是一個愚蠢的問題還是我失去了一些東西明顯。我一直在我的幫助下學習自己:)

感謝您的任何幫助,有一個很好的傢伙。

回答

0

如果您更改縱向上的中心或邊框,則應該將其更改回橫向... 也應在每次旋轉時更改滾動視圖的contentSize。

嘗試這樣的事情......

- (void)didRotate:(NSNotification *)notification 
{ 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    if (orientation == UIDeviceOrientationLandscapeRight) 
    { 
     [UIView animateWithDuration:0.2f animations:^{ 
      self.view.frame = CGRectMake(0, 0, 480.0, 320.0); 
      self.view.center = CGPointMake(240.0, 160.0); 

      self.view.layer.transform = CATransform3DMakeRotation(-M_PI/2, 0, 0.0, 1.0); 
      [self.scrollViewImages setContentSize:CGSizeMake(self.view.frame.size.width*self.images.count, 320.0)]; 
      [self.scrollViewImages setContentOffset:CGPointMake(0, 0) animated:YES]; 
     } completion:^(BOOL finished) { 

     }]; 
    } else if(orientation == UIDeviceOrientationPortrait) { 
     [UIView animateWithDuration:0.2f animations:^{ 
      self.view.frame = CGRectMake(0, 0, 320.0, 480.0); 
      self.view.center = CGPointMake(160.0, 240.0); 
      self.view.transform = CGAffineTransformIdentity;    

      [self.scrollViewImages setContentSize:CGSizeMake(self.view.frame.size.width*self.images.count, 320.0)]; 
      [self.scrollViewImages setContentOffset:CGPointMake(0, 0) animated:YES]; 

     } completion:^(BOOL finished) { 

     }]; 
    } 
}