在Swift中,无论如何都知道哪个对象被刷过?

时间:2015-04-25 02:54:50

标签: ios swift

我想将发件人 func application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: (([NSObject : AnyObject]!) -> Void)!) { if let userInfo = userInfo, request = userInfo["SiteName"] as? String { let siteName = userInfo["SiteName"] as? String reply(["Message":"Received launch request from \(siteName)"]) UIApplication.sharedApplication().openURL(NSURL(string: "DSExtension://more")!) } } 传递给函数redBox。我不知道如何传递不是leftSwipeFunc的参数。如果你知道答案,请帮助我。

UISwipeGestureREcognizer

2 个答案:

答案 0 :(得分:2)

手势识别器有一个名为view的属性,它是附加到的UIView。因此,您可以在leftSwipeFunc内使用它来获取视图:

func leftSwipeFunc(gesture: UISwipeGestureRecognizer) {
    let swipedView = gesture.view

    // Assuming redBox is a property of your view controller
    if swipedView == redBox {
        println("the redBox was swiped")
    } else {
        println("some other view was swiped")
    }
}

答案 1 :(得分:0)

您可以使用locationInView在视图中找到滑动的位置。

leftSwipeFunc中,找到触摸屏的CGPoint,然后检查它是否在所需的视图中。

let location = gesture.locationInView(self.view)

if CGRectContainsPoint(redBox, location) {
    // redBox was swiped, do something
}