Ответ 1
Мне очень нравится этот вопрос. Я также нахожу чередующуюся анимацию вращения для некоторых интерфейсов. Здесь, как бы я реализовал то, что вы нарисовали. Простой @interface
будет просто отлично.
Примечание: Я использую ARC.
#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
.
Примечание. Обратите внимание: если устройство повернуто так, как все касается не кнопок, устройство все еще находится на портрете, но ваш ответ на мой комментарий, похоже, указывает на то, что проблема для вас.
Не стесняйтесь оставлять комментарий, если у вас есть родственный вопрос.