我正在尝试制作一个应用程序,我必须在其中触摸button
正在向上移动屏幕的人。我正在使用CADisplayLink
这个。我的代码中的问题是它创建了一个新按钮而不是使用特定按钮:
@IBOutlet var label: UILabel!
@IBOutlet var button2: UIButton!
@IBAction func button1(sender: UIButton) {
label.hidden = true
button2 = UIButton(type: UIButtonType.System) as UIButton
button2.frame = CGRectMake(120, 400, 100, 100)
button2.setTitle("Test Button", forState: UIControlState.Normal)
button2.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
let displayLink = CADisplayLink(target: self, selector: "handleDisplayLink:")
displayLink.addToRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
}
func handleDisplayLink(displayLink: CADisplayLink) {
var buttonFrame = button.frame
buttonFrame.origin.y += -2
button2.frame = buttonFrame
if button2.frame.origin.y <= 50 {
displayLink.invalidate()
}
}
func buttonAction(sender: UIButton) {
sender.alpha = 0
label.hidden = false
}
override func viewDidLoad() {
super.viewDidLoad()
label.hidden = true
}
谢谢你。安东