我在收到来自解析的通知时尝试显示自定义视图。 此视图显示动画,并隐藏另一个动画。此视图还有一个uitapgesturerecognizer,需要在用户点击视图时触发。 我的问题是,当第二个动画被触发时,自定义视图的uitapgesture不起作用:\
有什么想法吗?我粘贴代码。 谢谢!
func doManageObjectNotification(notification: COPushNotification){
mainView = UIApplication.sharedApplication().keyWindow!
customView = CustomNotificationView()
let height = customView.calculateViewHeight()
customView.frame = CGRectMake(0, -height, mainView.frame.width, height)
customView.targetMethod = notificationWasTapped
customView.setContent(notification)
customView.alpha = 0
mainView.addSubview(customView)
UIView.animateWithDuration(0.75, delay: 0, options: [UIViewAnimationOptions.CurveEaseInOut, UIViewAnimationOptions.AllowUserInteraction], animations: { () -> Void in
// Show the view
self.customView.frame.origin.y = 0
self.customView.alpha = 1
}) { (Bool) -> Void in
UIView.animateWithDuration(0.75, delay: 5, options: [UIViewAnimationOptions.CurveEaseInOut, UIViewAnimationOptions.AllowUserInteraction], animations: {
// Hide the view
self.customView.alpha = 0
}, completion: { finished in
self.customView.removeFromSuperview()
self.customView = nil
})
}
}
答案 0 :(得分:2)
我同意Lion的答案,但我想在动画期间关注customView.frame.origin.y = 0
:如果您使用自动布局并尝试更改框架尺寸或位置如果涉及正确的约束,您可以禁用约束效果,从而导致警告和意外的视图尺寸和移动。多次出现此问题时,UITapGestureRecognizer
会停止响应。
最好的方法是创建IBOutlets约束并使用它(例如):
@IBOutlet weak var customViewTopConstraint: NSLayoutConstraint
...
UIView.animateWithDuration(0.75, delay: 0, options: [UIViewAnimationOptions.CurveEaseInOut, UIViewAnimationOptions.AllowUserInteraction], animations: { () -> Void in
// Show the view
self.customViewTopConstraint.constant = 0
答案 1 :(得分:1)
要在动画期间处理点按,您应该实施$ awk -F: 'FNR==NR {count[$2]++; next} count[$2]>1 {$0=$0 OFS "#"++times[$2]}1' file file
1:Jose da Silva #1
2:Jose da Silva #2
3:Fulano de Tal
4:Jose da Silva #3
5:Sicrano Pereira #1
6:Ze Ruela
7:Sicrano Pereira #2
8:Jose da Silva #4
方法。通过这种方式,您可以检测到触摸,然后检查触摸是否来自您的视图,如果是,则可以执行所需的任务。
希望这会有所帮助:)