2010-07-31 13 views

cevap

18

Bunu, bir portre ve bir yatay düzen ile bir uygulama almak için IB aracılığıyla yapabilir veya program aracılığıyla yapabilirsiniz. Bu programatik yolla ilgilidir.

, yönelim değişikliği bildirim alabilmek

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
       selector:@selector(orientationChanged) 
       name:UIDeviceOrientationDidChangeNotification 
       object:nil]; 

kullanın ve ayarlamak gerekir, (bu not dışarı bırakılır bir proje ve çizgilerin bir sürü copypasted olan böyle bir işlev eklemek için özel durumunuza transformasyon)

bitirdiniz
-(void)orientationChanged 
{ 
    UIDeviceOrientation o = [UIDevice currentDevice].orientation; 

    CGFloat angle = 0; 
    if (o == UIDeviceOrientationLandscapeLeft) angle = M_PI_2; 
    else if (o == UIDeviceOrientationLandscapeRight) angle = -M_PI_2; 
    else if (o == UIDeviceOrientationPortraitUpsideDown) angle = M_PI; 

    [UIView beginAnimations:@"rotate" context:nil]; 
    [UIView setAnimationDuration:0.7]; 
    self.rotateView.transform = CGAffineTransformRotate(
           CGAffineTransformMakeTranslation(
            160.0f-self.rotateView.center.x, 
            240.0f-self.rotateView.center.y 
           ),angle); 
    [UIView commitAnimations]; 
} 

, şöyle bildirimleri durdurmak:

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] removeObserver:self]; 
+0

Hmm, bu benim için mükemmel çalışmıyor çünkü bir UIView içindeki UIImageView/UIView'i döndürmeyecek. Bunun yerine tüm UIView'i yalnızca alt görünümü değil. – Joshua

+0

, daha sonra, döndürdüğünüz alt görünüm olan 'self.rotateView' öğesini yapar. – mvds

+3

'M_PI/2.0f' yerine' M_PI_2' kullanmalısınız –