Hel*_*ood 22 iphone xcode ios autolayout size-classes
我正在调整我的UI应用程序,但我遇到了一个我无法解决的问题.
我可以看到Compact高度会影响4.7英寸以下的所有iPhone,但我的用户界面很好,除了iPhone 4S(3.5英寸).
我不想修改4.7英寸以下的所有iPhone的布局,只需要修改iPhone 4S,同时我不想遗漏这个设备.
有任何解决方法,所以我可以设置修正案,但仅适用于3.5英寸的肖像?或者我应该告别那里的1亿台设备?
我知道这是一个棘手的问题,几乎是民意调查,但从技术上讲,我想在这里找到最好的方法.
Pav*_*eev 16
iPhone 3.5英寸没有尺寸等级.
所以我已经为NSLayoutConstraint创建了一个类类别,可以在Interface Builder中编辑它,它很容易使用:
@interface NSLayoutConstraint (Extensions)
@property (nonatomic) IBInspectable CGFloat iPhone3_5_Constant;
@end
Run Code Online (Sandbox Code Playgroud)
-
@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
Run Code Online (Sandbox Code Playgroud)
小智 13
一个对我有用的方法是对所有紧凑大小类使用相同的约束,但是使用大于或等于约束和优先级的组合来修改视图在iPhone 4的较小屏幕上的定位方式.
我在数字键盘视图的顶部和设置为大于或等于160(优先级为1000)的超级视图之间存在约束,并且键盘视图底部与底部之间存在约束. superview设置为常量30(但优先级低于750).
这意味着在iPhone 4上没有足够的空间可以在键盘上方160点以上,并且在30点以下,那就是下面的空间.
虽然这种方法可能并不适用于所有情况,但我建议您考虑是否有一组优先级可以让您的视图在小屏幕上以您想要的方式进行调整.
Pet*_*rdk 13
Swift 3版本的Pavel Alexeev的解决方案.在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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
@all我不能把事情缩小,因为我正在处理的挑选视图恰好只有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)
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11976 次 |
最近记录: |