gpt4 book ai didi

iphone - 在处理多个方向时,我应该使用哪些最佳实践?

转载 作者:行者123 更新时间:2023-11-29 04:53:01 24 4
gpt4 key购买 nike

请原谅我的无知。传统上我一直在做这样的事情,但感觉这是很多不必要的工作,我不确定是否有更简单的方法来完成这个任务。

// 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...
}
}

我是否应该遵循更好的协议(protocol)来实现这一目标,或者这或多或少是每个人处理多个方向的方式?

最佳答案

查看所有图形对象的 autoResizingMask 选项。这应该有帮助。

关于iphone - 在处理多个方向时,我应该使用哪些最佳实践?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8499916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com