2010-07-31 18 views

उत्तर

18

आप आईबी के माध्यम से ऐसा कर सकते हैं, एक चित्र और में लैंडस्केप लेआउट के साथ एप्लिकेशन प्राप्त करने के लिए, या आप इसे प्रोग्राम के रूप में कर सकते हैं। यह प्रोग्रामेटिक तरीके से है।

उन्मुखीकरण के परिवर्तन पर सूचनाएं प्राप्त करने,

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

का उपयोग करें और (इस पर ध्यान दें एक परियोजना और लाइनों का एक बहुत से copypasted है बाहर छोड़ दिया जाता है इस तरह एक समारोह जोड़ने के लिए, आप धुन करने की आवश्यकता होगी करने के लिए अपने विशिष्ट स्थिति के लिए परिवर्तन)

-(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]; 
} 

जब आप कर रहे हैं, इसलिए जैसे सूचनाएं बंद:

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

हम्म, यह मेरे लिए पूरी तरह से काम करने के लिए के रूप में यह सिर्फ UIImageView/UIView जो एक और UIView अंदर है बारी बारी से नहीं होगा नहीं लगता है। इसके बजाय यह पूरे UIView को केवल उप-दृश्य को घुमाता है। – Joshua

+0

तो 'self.rotateView' बस उप-दृश्य आपको घुमाया है करना चाहते हैं। – mvds

+3

आपको 'M_PI/2.0f' के बजाय' M_PI_2' का उपयोग करना चाहिए –