Bu soruyu gerçekten çok seviyorum. Ayrıca bazı arayüzler için rotasyon animasyonunu da buluyorum. Resimde gördüğün şeyi nasıl uygulayacağım. Basit bir @interface
sadece iyi olacak. Not: ARC kullanıyorum.
ControllerWithRotatingButtons.m:
#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
uygun çıkış bağlantıları .xib
düğmelerin yapılır
#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
Ve işte bu kadar. Cihazınızı döndürdüğünüzde Şimdi ekran döndürme olmayacak ama düğmeler olarak gösterilir olacaktır: Elbette
sadece düğmenin etiket sadece yerine _buttonA.titleLabel
dönüşümü geçerli olacak çevirmek istiyorum.
Not: cihaz kadarıyla düğmelerle ilgili herhangi dokunuşlar ilgili olarak döndürülür kez cihaz portre hala ama benim yorumum cevabınız bu sizin için bir sorun değil göstermektedir görünüyor unutmayın.
İlgili bir sorunuz varsa yorum yazmaktan çekinmeyin.
+1 Güzelce görüntülenen soru için +1 – Till
Durum çubuğunun sabit kalmasını ister misiniz, yoksa resimde yalnızca göz ardı edilmiş mi? – NJones
@NJones Temel hedefim olmasa da, hala devam ederse tamam olur! Benim mevcut uygulamada, alt görünümler (ya da kök pencere?) Dönüyor olduğundan, alt görünümler bir "komik yol" boyunca hareket eder. – ragnarius