मुझे वास्तव में यह प्रश्न पसंद है। मुझे कुछ इंटरफेस के लिए रोटेशन एनीमेशन जारिंग भी मिलती है। यहां बताया गया है कि मैंने आपके द्वारा चित्रित किए गए कार्यों को कैसे कार्यान्वित किया है। एक साधारण @interface
ठीक होगा। नोट: मैं एआरसी का उपयोग कर रहा हूँ।
#import <UIKit/UIKit.h>
@interface ControllerWithRotatingButtons : UIViewController
@property (strong, nonatomic) IBOutlet UIButton *buttonA;
@property (strong, nonatomic) IBOutlet UIButton *buttonB;
@property (strong, nonatomic) IBOutlet UIButton *buttonC;
@end
उचित आउटलेट कनेक्शन .xib
में बटन के लिए बना रहे हैं:
ControllerWithRotatingButtons.m:
#import "ControllerWithRotatingButtons.h"
@implementation ControllerWithRotatingButtons
@synthesize buttonA = _buttonA;
@synthesize buttonB = _buttonB;
@synthesize buttonC = _buttonC;
-(void)deviceRotated:(NSNotification *)note{
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
CGFloat rotationAngle = 0;
if (orientation == UIDeviceOrientationPortraitUpsideDown) rotationAngle = M_PI;
else if (orientation == UIDeviceOrientationLandscapeLeft) rotationAngle = M_PI_2;
else if (orientation == UIDeviceOrientationLandscapeRight) rotationAngle = -M_PI_2;
[UIView animateWithDuration:0.5 animations:^{
_buttonA.transform = CGAffineTransformMakeRotation(rotationAngle);
_buttonB.transform = CGAffineTransformMakeRotation(rotationAngle);
_buttonC.transform = CGAffineTransformMakeRotation(rotationAngle);
} completion:nil];
}
-(void)viewDidLoad{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceRotated:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void)viewDidUnload{
[super viewDidUnload];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
और बस हो गया। अब जब आप अपने डिवाइस बारी बारी से स्क्रीन बारी बारी से होगा नहीं, लेकिन बटन के रूप में दिखाया जाएगा:
बेशक
अगर आप केवल बटन के लेबल चालू करने के लिए आप बस के बजाय _buttonA.titleLabel
को बदलने लागू होगा चाहते हैं।
नोट: कृपया ध्यान दें कि एक बार डिवाइस के रूप में जहाँ तक बटन पर नहीं किसी भी छूता है का सवाल है घुमाया डिवाइस चित्र में अब भी है, लेकिन मेरी टिप्पणी करने के लिए आपकी प्रतिक्रिया है कि आप के लिए एक समस्या नहीं है इंगित करता है।
यदि आप एक संबंधित सवाल है एक टिप्पणी छोड़ने के लिए स्वतंत्र महसूस।
अच्छी तरह से सचित्र प्रश्न के लिए +1 – Till
कि सिर्फ एक उदाहरण में अनदेखी की है आप चाहते हैं स्थिति पट्टी अभी भी रहने के लिए, या है? – NJones
@NJones हालांकि यह मेरी प्राथमिक उद्देश्य नहीं है, यह ठीक हो सकता है अगर यह अभी भी बने हुए हैं! मेरे वर्तमान कार्यान्वयन में, सबव्यूज़ "मजेदार पथ" के साथ आगे बढ़ते हैं क्योंकि सुपर व्यू (या रूट विंडो?) घूर्णन कर रहा है। – ragnarius