0
請原諒我的無知。傳統上,我一直在做這樣的事情,但感覺像很多不必要的工作,我不確定是否有更簡單的方法來實現這一點。在處理多個方向時,我應該使用哪些最佳做法?
// logoView dimensions
static const CGFloat LOGO_VIEW_X_PORT = 42;
static const CGFloat LOGO_VIEW_Y_PORT = 20;
static const CGFloat LOGO_VIEW_W_PORT = 237;
static const CGFloat LOGO_VIEW_H_PORT = 82;
//
static const CGFloat LOGO_VIEW_X_LAND = 142;
static const CGFloat LOGO_VIEW_Y_LAND = 20;
static const CGFloat LOGO_VIEW_W_LAND = 237;
static const CGFloat LOGO_VIEW_H_LAND = 82;
- (void)viewDidLoad {
[super viewDidLoad];
// init logo view
self.logoView = [[UIImageView alloc] initWithImage:...];
// determine device orientation and set dimensions
if (self.interfaceOrientation == UIDeviceOrientationPortrait ||
toInterfaceOrientation == UIDeviceOrientationPortraitUpsideDown) {
self.logoView.frame = CGRectMake(LOGO_VIEW_X_PORT, LOGO_VIEW_Y_PORT, LOGO_VIEW_W_PORT, LOGO_VIEW_H_PORT);
} else {
self.logoView.frame = CGRectMake(LOGO_VIEW_X_LAND, LOGO_VIEW_Y_LAND, LOGO_VIEW_W_LAND, LOGO_VIEW_H_LAND);
}
[self.view addSubview:self.logoView];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIDeviceOrientationPortrait ||
toInterfaceOrientation == UIDeviceOrientationPortraitUpsideDown) {
self.logoView.frame = CGRectMake(LOGO_VIEW_X_PORT, LOGO_VIEW_Y_PORT, LOGO_VIEW_W_PORT, LOGO_VIEW_H_PORT);
// long list of other views...
} else {
self.logoView.frame = CGRectMake(LOGO_VIEW_X_LAND, LOGO_VIEW_Y_LAND, LOGO_VIEW_W_LAND, LOGO_VIEW_H_LAND);
// long list of other views...
}
}
有沒有更好的協議,我應該下做到這一點,還是這或多或少大家如何處理多個方向?
您可以使用autorotatingmasks代替。 – PengOne 2011-12-14 05:47:44