【发布时间】:2015-10-20 20:36:05
【问题描述】:
我的问题很简单。
我目前正在继承 UIButton 以创建一些自定义动画。但是,当我将translatesAutoresizingMaskIntoConstraints 设置为false 时,我的视图会移动到左上角。但是,当我将其设置为 false 或将类更改为 UIView 或 UIControl 时,此问题不再出现。
这是我的代码:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = TestA(frame: CGRectMake(100, 100, 100, 100))
button.backgroundColor = UIColor.blackColor()
self.view.addSubview(button)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
class TestA : UIControl {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
}
有人知道发生了什么吗?
【问题讨论】:
标签: ios swift uibutton autolayout