0

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
}

ありがとうございました。アントン

4

1 に答える 1