[英]event.touchesForView().AnyObject() not working in Xcode 6.3
這之前完美無缺:
func doSomethingOnDrag(sender: UIButton, event: UIEvent) {
let touch = event.touchesForView(sender).AnyObject() as UITouch
let location = touch.locationInView(sender)
}
但在Xcode 6.3中,我現在得到錯誤:
無法調用沒有參數的'AnyObject'
我該如何解決?
在1.2中, touchesForView
現在返回本機Swift Set
而不是NSSet
,而Set
沒有anyObject()
方法。
它確實有first
一種方法,這是一回事。 另外請注意,您將無法使用as?
任何更多,你必須使用as?
處理零可能性,這是一種方法:
func doSomethingOnDrag(sender: UIButton, event: UIEvent) {
if let touch = event.touchesForView(sender)?.first as? UITouch,
location = touch.locationInView(sender) {
// use location
}
}
func doSomethingOnDrag(sender: UIButton, event: UIEvent) {
let buttonView = sender as! UIView;
let touches : Set<UITouch> = event.touchesForView(buttonView)!
let touch = touches.first!
let location = touch.locationInView(buttonView)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.