Transition between controllers is jumpy - ios

I have some small black flickering in the transition moment between controllers.
I have to load many things to the new controller before I show it, and I pass it some UIImage argument called "Art".
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller:ModelController = storyboard.instantiateViewController(withIdentifier: "ModController") as! ModelController
controller.artwork=art //pass this to load the new
let transition = CATransition()
transition.duration = 0.30
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
view.window!.layer.add(transition, forKey: kCATransition)
present(controller, animated: false, completion: nil)
On the new controller, I load everything after :
override func viewDidLoad() {
super.viewDidLoad()
//load scroller here

Related

PushViewController() causes popover to be full screen

I want to push a popover on top of my view controller. Currently, this code resides in my subclass of UIView:
func presentGameOver() {
let transition: CATransition = CATransition()
transition.duration = 0.75
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.type = CATransitionType.fade
let currentController = (getCurrentViewController() as! UINavigationController).topViewController!
currentController.navigationController!.view.layer.add(transition, forKey: nil)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "GameOverViewController") as! GameOverViewController
vc.modalPresentationStyle = UIModalPresentationStyle.popover
vc.highScore = highScore
vc.score = score
vc.FONT_H = FONT_H
vc.delegate = self
currentController.navigationController?.pushViewController(vc, animated: false)
}
This is my class declaration:
class GridView: UIView, ModalHandler, UIPopoverPresentationControllerDelegate {
I have these two methods as well:
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
return false
}
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.none
}
In the storyboard, for the view controller I want to be a popover, I set the content size(this and this).
However, when the popover is shown, it is shown full screen. When I previously used popovers, I would present them. Does popover display not work using pushViewController()?
The animation is quite complicated if you have little experience. The following code may give you some clues.
func presentGameOver() {
let transition: CATransition = CATransition()
transition.duration = 0.75
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.type = CATransitionType.fade
let currentController = (getCurrentViewController() as! UINavigationController).topViewController!
currentController.navigationController!.view.layer.add(transition, forKey: nil)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "GameOverViewController") as! GameOverViewController
vc.modalPresentationStyle = UIModalPresentationStyle.popover
vc.highScore = highScore
vc.score = score
vc.FONT_H = FONT_H
vc.delegate = self
if let popoverPresentationController = vc.popoverPresentationController{
popoverPresentationController.delegate = self;
popoverPresentationController.sourceView = self
popoverPresentationController.sourceRect = CGRect.init(x: 200, y: 200, width: 500, height: 300)}
currentController.present(vc, animated: false) {}
}

Slide menu not showing on the view controller which is presented on another view controller

I am using the Side menu controller. The Side view controller works fine but when another view controller B is presented over another view controller A. The side menu doesnot appears on the view controller B while swiping. The code for embedding the side menu controller is:
let homeViewController = UIStoryboard(name: "Home", bundle: nil).instantiateViewController(withIdentifier: "homeLandingIdentifier") as? HomeLandingViewController
let leftViewController = UIStoryboard(name: "SideBar", bundle: nil).instantiateViewController(withIdentifier: "sideBar") as? SideBarViewController
let mainNavigationController: UINavigationController = UINavigationController(rootViewController: homeViewController!)
let slideMenuController = SlideMenuTrackerController(mainViewController: mainNavigationController, leftMenuViewController: leftViewController!)
AppDelegate.sharedInstance().window?.rootViewController = slideMenuController
leftViewController?.mainViewController = mainNavigationController
slideMenuController.automaticallyAdjustsScrollViewInsets = true
AppDelegate.sharedInstance().window?.backgroundColor = UIColor(red: 236.0, green: 238.0, blue: 241.0, alpha: 1.0)
AppDelegate.sharedInstance().window?.makeKeyAndVisible()
The code for presenting the view controller is:
let viewcontroller = UIStoryboard(name: "Home", bundle: nil).instantiateViewController(withIdentifier: "homeSearchIndentifier") as? HomeSearchViewController
let searchViewController = UIStoryboard(name: "Home", bundle: nil).instantiateViewController(withIdentifier: "searchRideIdentifier") as? SearchRideViewController
searchViewController?.parentView = .homeLandingPage
let duration = 0.4
let transition: CATransition = CATransition()
transition.duration = duration
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromBottom
self.navigationController!.view.layer.add(transition, forKey: kCATransition)
self.navigationController?.pushViewController(viewcontroller!, animated: false)
viewcontroller?.present(searchViewController!, animated: true, completion: nil)
}
The side menu which i am using is:
Side menu

How to push a UIViewController without using a navigational controller?

I am trying to imitate the behaviour that can be observed with SFSafariViewController. When presented, the push transition animation is used just like with a root UINavigationalController. When doing an edge pan swipe right, the pop transition follows.
let url = URL(string: "http://google.com")!
let safari = SFSafariViewController(url: url)
present(safari, animated: true, completion: nil)
However, I need the same transition to work with any other UIViewController.
let storyboard = UIStoryboard(name: "Place", bundle: nil)
let controller = storyboard.instantiateInitialViewController()
present(controller!, animated: true, completion: nil)
Using CATransition you can able to change the animation direction while presenting the ViewController
let controller = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
view.window!.layer.add(transition, forKey: kCATransition)
present(controller, animated: false, completion: nil)
#Fuxing, It is not possible to push a view controller without navigation controller.Ther are two option to push a view controller.
Add a navigation controller to your viewController in the storyboard.
Create an object of the navigation controller.
let viewToPush = YourViewController()
let nav = UINavigationController(rootViewController: viewToPush)
nav.pushViewController(nav, animated: true)

how to manually adjust view switching speed with swipe gesture

I am using CATransition for the next view to present over another from right. Now i want to control this view transition using swipe gesture so that user can swipe from left to right and next view present on screen with the thumb speed and position . So that user can feel the realness
my transition code is
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc : drawer = storyboard.instantiateViewControllerWithIdentifier("drawerID") as! drawer
let transition: CATransition = CATransition()
let timeFunc : CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.duration = 0.50
transition.timingFunction = timeFunc
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight //kCATransitionFromLeft
self.navigationController!.view.layer.addAnimation(transition, forKey: kCATransition)
self.navigationController!.pushViewController(vc, animated: false)

iOS presenting view controller animated as 'Push' (right-left animation)

Currently, I have a view controller presenting other view controller. What I'm trying to do is to recreate the default animation used when pushing a view controller.
My current approach is:
FirstViewController:
#IBAction private func push(sender: AnyObject) {
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("SecondViewController")
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
view.window?.layer.addAnimation(transition, forKey: kCATransition)
presentViewController(vc, animated: false, completion: nil)
}
SecondViewController:
#IBAction private func pop(sender: AnyObject) {
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromLeft
view.window?.layer.addAnimation(transition, forKey: kCATransition)
dismissViewControllerAnimated(false, completion: nil)
}
It is almost working, but I have a weird behaviour, I'm having a kind of black screen/flash when transitioning between view controllers. I already tried changing window.backgroundColor but it is not fixing the issue.
Thanks in advance 0_0...
The trouble is merely that what you're doing is not how to customize the animation for a present/dismiss transition. Apple has provided you with a clear, well-establish, official way to do that, and what you're doing is not it. You need to give your presented view controller a transitioningDelegate along with implementations of animationControllerForPresentedController: and animationControllerForDismissedController:, and implement the UIViewControllerAnimatedTransitioning protocol, possibly along with a custom UIPresentationController subclass.

Resources