我希望改变我的代码从左到右的过渡,但这个CustomeSegue只显示下来,谢谢!!!
class FirstCustomSegue: UIStoryboardSegue {
override func perform() {
// Assign the source and destination views to local variables.
var firstVCView = self.sourceViewController.view as UIView!
var secondVCView = self.destinationViewController.view as UIView!
// Get the screen width and height.
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
// 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.4, 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)
}
}
}
答案 0 :(得分:2)
从你的代码:
你不应该使用宽度而不是高度吗?
// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight)
也在这里
// Animate the transition.
UIView.animateWithDuration(0.4, 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)
}
答案 1 :(得分:1)
在您必须离开的按钮操作上将此代码添加到源视图控制器。
func performAnimation()
{
var mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
// Identifier name for the navigation controller
var initialNavigationController = mainStoryboard.instantiateViewControllerWithIdentifier("initialNavigationController") as! UINavigationController
//Identifier name for the view controller
var mainVC = mainStoryboard.instantiateViewControllerWithIdentifier("startingViewController") as! DestinationViewControllername
initialNavigationController.viewControllers = [mainVC]
self.presentViewController(initialNavigationController, animated: false, completion: nil)
(mainVC as DestinationViewControllername).DestinationRespondSelector()
}
在目标视图控制器中添加以下代码
var TransistionFromSourceVC = false
func DestinationRespondSelector()
{
TransistionFromSourceVC = true
}
func ViewAndAnimateIt()
{
println("here")
TransistionFromSourceVC = false
var mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
// Identifier name for the navigation controller
var mainNavigationController = mainStoryBoard.instantiateViewControllerWithIdentifier("initialNavigationController") as! UINavigationController
//Identifier name for the view controller
var SourceVC = mainStoryBoard.instantiateViewControllerWithIdentifier("SourceViewController") as! SourceVC
mainNavigationController.viewControllers = [SourceVC]
self.view.addSubview(mainNavigationController.view)
self.view.bringSubviewToFront(mainNavigationController.view)
UIView.animateWithDuration(0.3, animations: {
mainNavigationController.view.frame.origin.x += self.view.frame.width
}) { (finished) -> Void in
mainNavigationController.view.removeFromSuperview()
}
}
在目标viewWillappear
中添加此代码 override func viewWillAppear(animated: Bool) {
if TransistionFromSourceVC
{
ViewAndAnimateIt()
}
}
对源和目标viewController进行相应的更改。