2010-09-03 13 views
5

अपने iPhone इंटरफ़ेस घूमता है, मैं एक UIViewController ... की तरह की एक विशिष्ट UIView के लिए एक फीका-इन/फीका-बाहर करना चाहते हैं जब ...फीका-इन/फीका-बाहर एक अंतरफलक रोटेशन के दौरान

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.3]; 
    theView.alpha = 0; 
    [UIView commitAnimations]; 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.3]; 
    theView.alpha = 1; 
    [UIView commitAnimations]; 
} 

लेकिन एनीमेशन रोटेशन शुरू होने से पहले खत्म नहीं करता है (हम दृश्य स्वयं आकार बदलने शुरू देख सकते हैं) ...

वहाँ रोटेशन शुरू देरी करने के लिए एक तरीका है?

"अवधि" घूर्णन एनीमेशन की अवधि है, है ना?

+0

हाय, आपने अपनी समस्या का समाधान कैसे किया? – sergiobuj

+0

मैंने इसे हल नहीं किया। मैं बस एनीमेशन अवधि 0.1s सेट –

उत्तर

7

मैंने पाया कि पिछले एनीमेशन के समान समय के लिए वर्तमान रन लूप चलाना, वास्तव में रोटेशन में देरी हुई थी।

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    [UIView animateWithDuration:0.25 animations:^{ 
     theview.alpha = 0.0; 
    }]; 

    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; 
} 
0

आपकी समस्या इस तथ्य से उत्पन्न होती है कि उस समय तक रोटेट टॉइंटरफेसऑरिएंटेशन: कहा जाता है, दृश्य को घूर्णन करने के पहले से ही इसकी ओरिएंटेशन प्रॉपर्टी सेट है और रोटेशन को संभालने वाला एनीमेशन ब्लॉक भी अलग थ्रेड पर चलाने के लिए तैयार है। the documentation से:

इस विधि को दृश्य को घुमाने के लिए उपयोग किए गए एनीमेशन ब्लॉक के भीतर से कहा जाता है। आप इस विधि को ओवरराइड कर सकते हैं और दृश्य रोटेशन के दौरान होने वाले अतिरिक्त एनिमेशन को कॉन्फ़िगर करने के लिए इसका उपयोग कर सकते हैं।

मैं shouldAutorotateToInterfaceOrientation अधिभावी सुझाव है: समर्थित झुकाव के लिए हाँ लौटने से पहले अपने एनीमेशन आग विधि:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
     // Return YES for supported orientations 
     if (interfaceOrientation == (UIDeviceOrientationPortrait || UIDeviceOrientationPortraitUpsideDown) { 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:0.3]; 
     theView.alpha = 0; 
     [UIView commitAnimations]; 
     } else { 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:0.3]; 
     theView.alpha = 1; 
     [UIView commitAnimations]; 
     } 
     return YES; 
} 

इस एनीमेशन यह सुनिश्चित करना चाहिए चलाता है इससे पहले कि आप कभी UIViewController के उन्मुखीकरण सेट और रोटेशन आग एनीमेशन। डिवाइस हार्डवेयर की गति के आधार पर आपको जो प्रभाव दिख रहा है उसे प्राप्त करने के लिए आपको थोड़ी देर देनी पड़ सकती है।

संबंधित मुद्दे