访问'<>'符号内的值

时间:2018-11-27 11:44:01

标签: ios swift uiimageview uitapgesturerecognizer

我有一个手势识别器,如下所示:

@objc func handleTap(_ sender: UITapGestureRecognizer) {
    var currentImage = sender.view
    print(currentImage)

}

并打印出来:

Optional(<UIImageView: 0x7ff72601ddd0; frame = (0 0; 414 414); opaque = NO; gestureRecognizers = <NSArray: 0x600000b541e0>; layer = <CALayer: 0x6000005be0c0>>)

如何获取UIImageViewsender.view的值?

P.S。

调用敲击识别器的代码如下:

var tap = UITapGestureRecognizer()

override func viewDidLoad() {
    super.viewDidLoad()

    tap = UITapGestureRecognizer(target: self, action: #selector(ViewController.handleTap(_:)))
    tap.numberOfTapsRequired = 1
    tap.numberOfTouchesRequired = 1

    imageView.addGestureRecognizer(tap)
    imageView.isUserInteractionEnabled = true
}

1 个答案:

答案 0 :(得分:2)

您可以使用

Future

如果100%确定,则直接

then()

OR

if let  currentImage = sender.view as? UIImageView {

}