ios - 在声明中调整iPhoneX/iPad/iPhone6的UIView位置

标签 ios objective-c xcode

更新一些旧代码,并修复了UIView中一个讨厌的按钮之外的所有问题,该按钮仅在某些设备上无法正确显示。

它适用于所有iPad设备,并且位置完美,并且适用于iPhoneX / XS和XR

但是,对于iPhone 5,5s,6,6s,7,8,按钮未正确显示。

我知道这是一个“肮脏”的修复程序,但是实际上这是一个导致问题的按钮,其余代码本身运行正常,所以我不想像这样重新发明轮子。

图像位置本身是这样设置的;

 #define IDIOM    UI_USER_INTERFACE_IDIOM()
#define IPAD     UIUserInterfaceIdiomPad

if ( IDIOM == IPAD ) {
     [nail5View setFrame:CGRectMake(638, 682, nail5View.frame.size.width, nail5View.frame.size.height)]; // was 358,582
} else {
[nail5View setFrame:CGRectMake(358, 582, nail5View.frame.size.width, nail5View.frame.size.height)];
}

nail5View.autoresizingMask = UIViewAutoresizingNone;
transform = CGAffineTransformMakeRotation(+0.9);
nail5View.transform = transform;

有没有办法我可以专门针对低于X的iPhone添加一个额外的位置呢?

最佳答案

您可以检查设备是否为iPhone 8plus或更低型号,例如thise

#define iPhone8AndLesser ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height <= 736)

如果要使用iPhone 8,请使用736装667
您可以使用进行检查
if ( IDIOM == IPAD ) {
     [nail5View setFrame:CGRectMake(638, 682, nail5View.frame.size.width, nail5View.frame.size.height)]; // was 358,582
} else {
if iPhone8AndLesser{
    //Your conditions here;
}else{
  [nail5View setFrame:CGRectMake(358, 582, nail5View.frame.size.width, nail5View.frame.size.height)];
}
}

关于ios - 在声明中调整iPhoneX/iPad/iPhone6的UIView位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60990765/

相关文章:

ios - ionic Cordova 不能运行ios

iphone - 在 iPhone 上的另一个 ViewController 上创建一个 View 弹出窗口

swift - 如何在swift中获取数组的元素类型

ios - SpriteKit - 在关节之间绘制动态线

iOS 用户界面测试 : How to find UITableViewCell's AccessoryView?

objective-c - iOS 5 阻止 ARC 桥接转换

ios - 关闭应用程序后,从相机拍摄的照片不会出现在 ImageView 中

objective-c - 方法参数(无效)与无无效声明(编译器错误)

objective-c - 在一个应用程序 xcode 中使用多个 sqlite 数据库

objective-c - 如何知道用户何时单击 WebView 中的目标 ="_blank"链接?