Ios 如何使此序列动画退出到右侧或左侧?-敏捷的
这段代码可以很好地使用向下的动画进行自定义分段转换。如何使动画看起来像是在向左或向右过渡 另外-我正在使用UISweepGestureRecognitor触发segue。它工作得很好,只是只要我轻轻一刷,就会出现这种情况。在用户将手指移开或至少进行更大的滑动之前,我如何允许该序列不发生。我需要为此使用滚动视图吗 下面是我的UISweepGestureRecognitor代码Ios 如何使此序列动画退出到右侧或左侧?-敏捷的,ios,swift,segue,swipe,Ios,Swift,Segue,Swipe,这段代码可以很好地使用向下的动画进行自定义分段转换。如何使动画看起来像是在向左或向右过渡 另外-我正在使用UISweepGestureRecognitor触发segue。它工作得很好,只是只要我轻轻一刷,就会出现这种情况。在用户将手指移开或至少进行更大的滑动之前,我如何允许该序列不发生。我需要为此使用滚动视图吗 下面是我的UISweepGestureRecognitor代码 override func viewDidLoad() { var swipeGestureRecognizer
override func viewDidLoad() {
var swipeGestureRecognizer: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "showSecondViewController")
swipeGestureRecognizer.direction = UISwipeGestureRecognizerDirection.Up
self.view.addGestureRecognizer(swipeGestureRecognizer)
}
下面的代码是我的动画代码
class FirstCustomSegue: UIStoryboardSegue {
override func perform() {
// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight)
// Access the app's key window and insert the destination view above the current (source) one.
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(secondVCView, aboveSubview: firstVCView)
// Animate the transition.
UIView.animateWithDuration(0.5, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight)
secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight)
}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
animated: false,
completion: nil)
}
}
}
动画方向 您只需更改初始帧和目标帧。目前,
secondVCView
的初始帧的X,Y原点0.0
,屏幕高度
,这意味着它位于屏幕底部的正下方。如果希望它从右侧显示,则需要将其更改为screenWidth
,0.0
然后,firstVCView
的目标帧将改变,原点为-screenWidth
,0.0
,而secondVCView
的目标帧将改变,原点为0.0
,0.0
override func perform() {
// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight)
// Access the app's key window and insert the destination view above the current (source) one.
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(secondVCView, aboveSubview: firstVCView)
// Animate the transition.
UIView.animateWithDuration(0.5, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0)
}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
animated: false,
completion: nil)
}
}
}
延迟刷卡
修改showSecondViewController
方法以接受uisweegestureerecognizer
参数并检查其state
属性。如果要在用户抬起手指时触发segue,请在状态
为UIgestureRecognitizerStateEnded
时触发segue
如果您想要更细粒度的控制,例如当他们刷过一定距离时,您需要检查UIgestureRecognitizerStateChanged
的状态并监视触摸的位置。我将把这作为一个练习留给读者,因为有很多例子可以在谷歌上快速搜索:)