एक क्लीनर तरीका रोटेशन के लिए UIInterfaceOrientation उपयोग करने के लिए नहीं है।
क्यों, क्योंकि तब आपकी इंटरफ़ेस या दृश्य 1 वास्तव में घूमता है। इसका मतलब है आप इसे वापस बारी बारी से करने के लिए इसे पुन: प्रदर्शित करने के लिए करने के बाद दृश्य 2 निकाल दिया जाता है की है।
इसके लिए क्षतिपूर्ति करने के लिए, मैं सरल UIDeviceOrientation अधिसूचनाओं की सदस्यता लेता हूं। काफी अलग है। देखें 1 autorotation इस विधि काम करने के लिए समर्थन करने के लिए नहीं है।
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
तो बस विधि detectOrientation को परिभाषित:
-(void) detectOrientation {
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
//load view 2
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
// load view 1
}
}
अब आप अपने विचारों का न autoratation समर्थन की जरूरत है viewDidLoad में निम्न कोड दर्ज करें! हालांकि आप एक लोड करने से पहले दृश्य 2 पर बदलना प्रदर्शन करने के लिए की आवश्यकता होगी:
-(void) transformView2ToLandscape {
NSInteger rotationDirection;
UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation];
if(currentOrientation == UIDeviceOrientationLandscapeLeft){
rotationDirection = 1;
}else {
rotationDirection = -1;
}
CGRect myFrame = CGRectMake(0, 0, 480, 300);
CGAffineTransform transform = [[self view2] transform];
transform = CGAffineTransformRotate(transform, degreesToRadians(rotationDirection * 90));
[[self view2] setFrame: myFrame];
CGPoint center = CGPointMake(myFrame.size.height/2.0, myFrame.size.width/2.0);
[[self view2] setTransform: transform];
[[self view2] setCenter: center];
}
Thats कैसे मैं अपने विचारों में autorotation के समर्थन के बिना ओ रोटेशन विचारों स्वैप।
स्रोत
2009-05-21 16:24:18
क्या मुझे प्रारंभिक टैबबारकंट्रोलर को subAass करना चाहिए ताकि इसमेंAAutorotateToInterfaceOrientation विधि को जोड़ा जा सके? यह टैबबार नियंत्रक आईबी और कुछ लाइनों को एप्लिकेशन प्रतिनिधि में एक कोड का उपयोग करके स्थापित किया गया है। मैंने सभी चरणों का पालन किया है, लेकिन किया गया RotateFromInterfaceOrientation नहीं कहा जाता है। –
ठीक है, मैंने tabBarController को उपclassed, addAutorotateToInterfaceOrientation जोड़ना और अब सबकुछ काम करता है। आपकी मदद के लिए बहुत बहुत शुक्रिया। सधन्यवाद। –
मैं UITabBarController का उपयोग नहीं करना पसंद करता हूं और इसके बजाय UITiewController को UITabBar के साथ उपयोग करना पसंद करता हूं। – mk12