UIControl 的高度不会在 UIScrollView 中以编程方式更改
Height of UIControl does not change programmatically within UIScrollView
当我在 viewDidLoad()
button.frame.size.height = 30
高度更改成功但是当 scrollViewDidScroll 调用按钮 return 到它的初始高度 -> 20
注意:当我改变按钮的高度时,我改变了 scrollView.contentSize.height += 10
(20 -> 30)
xcode 6.1 和 iOS 8.1
既然您使用的是自动布局,为什么不对按钮的高度添加约束?
如果您需要在运行时更改高度,则必须更改约束常量(您可以像访问任何其他 IBOutlet 一样访问 IB 中定义的约束),而不是框架。
编辑: 我假设您使用的是 Interface Builder,那么您可以使用以下代码在代码中显式添加对按钮高度的约束:
[self addConstraint:[NSLayoutConstraint constraintWithItem:yourButton
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:30.0]];
当我在 viewDidLoad()
button.frame.size.height = 30
高度更改成功但是当 scrollViewDidScroll 调用按钮 return 到它的初始高度 -> 20
注意:当我改变按钮的高度时,我改变了 scrollView.contentSize.height += 10
(20 -> 30)
xcode 6.1 和 iOS 8.1
既然您使用的是自动布局,为什么不对按钮的高度添加约束?
如果您需要在运行时更改高度,则必须更改约束常量(您可以像访问任何其他 IBOutlet 一样访问 IB 中定义的约束),而不是框架。
编辑: 我假设您使用的是 Interface Builder,那么您可以使用以下代码在代码中显式添加对按钮高度的约束:
[self addConstraint:[NSLayoutConstraint constraintWithItem:yourButton
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:30.0]];