尺寸类专门为肖像3.5英寸(iPhone 4S)XCode 6?

我在调整我的UI应用程序,但是我遇到了一个我无法解决的问题。

正如我所看到的紧凑高度影响所有iPhone的4.7英寸,但我的用户界面是很好的,除了iPhone 4S(3.5英寸)。

我不想修改4.7英寸以下所有iPhone的布局,只是iPhone 4S,同时我不想忽略这个设备。

有任何解决方法,所以我可以设置修改,但只是为了3.5英寸的肖像? 还是应该告别一亿个设备呢?

我知道这是一个棘手的问题,几乎是一个民意调查,但从技术上说,我想在这里find我最好的出路。

一个只为我工作的方法是对所有紧凑尺寸类使用相同的约束,但是使用大于或等于约束和优先级的组合来修改视图在iPhone 4的较小屏幕上的位置。

我在数字小键盘视图的顶部和它的超级视图之间有一个约束,该视图被设置为大于或等于160(优先级为1000),并且在小键盘视图底部和superview被设置为30的常量(但是具有750的低优先级)。

这意味着,在没有足够空间的键盘上方160点以上的30点的iPhone 4上,那么就是下面的空间了。

虽然这种方法可能不适用于所有情况,但是我鼓励您考虑是否有一组优先级可以让您的视图在小屏幕上以您希望的方式进行调整。

iPhone 3.5英寸没有尺寸等级。

所以我为NSLayoutConstraint做了一个类的类来在Interface Builder中编辑它,它非常容易使用:

在Interface Builder中为iPhone 4 / 4s设置大小类

 @interface NSLayoutConstraint (Extensions) @property (nonatomic) IBInspectable CGFloat iPhone3_5_Constant; @end 

 @implementation NSLayoutConstraint (Extensions) - (CGFloat)iPhone3_5_Constant { return self.constant; } - (void)setIPhone3_5_Constant:(CGFloat)iPhone3_5_Constant { if ([UIScreen mainScreen].bounds.size.height < 500) { self.constant = iPhone3_5_Constant; } } @end 

Swift 3版Pavel Alexeev的解决scheme。 在Swift中,不能在扩展中使用存储的属性,所以我们直接把它应用到constant属性中。

 extension NSLayoutConstraint { //We use a simple inspectable to allow us to set a value for iphone 4. @IBInspectable var iPhone4_Constant: CGFloat { set{ //Only apply value to iphone 4 devices. if (UIScreen.mainScreen().bounds.size.height < 500) { self.constant = newValue; } } get { return self.constant; } } } 

@我不能把事情做得更小,因为我正在处理pickerviews,而这些pickerviews对于UIPickerView(162.0,180.0和216.0)只有三个有效的高度。 大小和限制分开。

iPhone尺寸: http : //www.idev101.com/code/User_Interface/sizes.html,4S是独一无二的。

所以,虽然我的方法有点丑,但是把事情做完,几乎就在我的意思上。

所以我知道这远离Goodville,不要打我,只是为了分享:

 func checkForiPhone4S() { if (UIScreen.mainScreen().bounds.size.height == 480) { println("It is an iPhone 4S - Set constraints") listPickerView.transform = CGAffineTransformMakeScale(1, 0.8); var constraintHeight = NSLayoutConstraint(item: listPickerView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 100) self.view.addConstraint(constraintHeight) datePickerView.transform = CGAffineTransformMakeScale(1, 0.8); var constraintHeightDate = NSLayoutConstraint(item: datePickerView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 100) self.view.addConstraint(constraintHeightDate) } }