wMemory Warning and application Crash due to poor ViewController handling? - ios

I have a line of viewControllers set in line. The idea is to go through a process of questions etc. If i was to use the already set up way of changing view controller (through button - modal), i would have no problem with memory. I have tried it. However i need to change the views programmatically and not with buttons directly.
When i do this programmatically my memory usage just starts increasing as i go through the views, until eventually i get a Memory Warning and a crash.
To change the viewController i use custom UIStoryBoardSegue and also methods in the viewController files.
Here is how i do it:
Method in View Controller:
-(void)changeViewController
{
CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.timingFunction =[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.view.window.layer addAnimation:transition forKey:nil];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"enterInfoSecondViewController"];
[[[[[UIApplication sharedApplication]delegate]window]rootViewController]presentViewController:vc animated:NO completion:nil];
// [self dismissViewControllerAnimated:YES completion:nil];
//[self presentViewController:vc animated:NO completion:nil];
// [self dismissViewControllerAnimated:NO completion:nil];
}
In custom Segue:
-(void)perform
{
UIViewController *srcViewController = (UIViewController *)self.sourceViewController;
UIViewController*destViewController = (UIViewController *)self.destinationViewController;
CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[srcViewController.view.window.layer addAnimation:transition forKey:nil];
[srcViewController presentViewController:destViewController animated:NO completion:nil];
}
......
Somewhere I do it with segue and somewhere with the top method.
What am i doing wrong? i need help please :) Thank you in advance.

If all you need is to trigger the segue programmatically,
why not use -performSegueWithIdentifier:sender: ?

Related

Present transparent view controller on top of another viewcontroller with custom animation

I am trying to present a view controller on top of a view using the following code
HubViewController* vc = [HubViewController socialHubViewController];
CATransition* transition = [CATransition animation];
transition.duration = 3.0;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[vc.view.layer addAnimation:transition forKey:kCATransition];
[self presentViewController:vc animated:NO completion:^{
NSLog(#"vc: presented");
}];
Does not seem to work. Any help appreciated.
Issues based on navigation check your code.
or use that another way
HubViewController* vc = [HubViewController socialHubViewController];
CATransition* transition = [CATransition animation];
transition.duration = 3.0;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[vc.view.layer addAnimation:transition forKey:kCATransition];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:vc animated:NO completion:^{
NSLog(#"vc: presented");
}];
//UIViewController *topVc = [UIApplication sharedApplication].keyWindow.rootViewController;

dismissViewControllerAnimated not animating ViewController

I want to slide in a ViewController in the screen, and then at some point slide it out and go back to the presenting ViewController.
I use this code from my MainViewController to launch the modal, and then to dismiss it.
Why is the dismiss slide animation not working?
// Present a React Component sliding from the right on top of current ViewController
+ (void)presentSlidingFromRight:(UIViewController*)presented onViewController:(UIViewController*)presenterVC {
CATransition *transition = [[CATransition alloc] init];
transition.duration = 1;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[presenterVC.view.window.layer addAnimation:transition forKey:kCATransition];
[presenterVC presentViewController:presented animated:NO completion:nil];
}
// Dismiss a React Component sliding to the right
+ (void)dismissSlidingToRight:(UIViewController*)presented onViewController:(UIViewController*)presenterVC {
CATransition *transition = [[CATransition alloc] init];
transition.duration = 3;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[presenterVC.view.window.layer addAnimation:transition forKey:kCATransition];
[presenterVC dismissViewControllerAnimated:NO completion:nil];
}
Could you try changing this line:
[presenterVC dismissViewControllerAnimated:NO completion:nil];
for this one:
[presenterVC dismissViewControllerAnimated:YES completion:nil];
Update
Make sure you are calling your static functions on the Main Thread

Dropdown and bounce Segue anitimation

I am trying to replicate the following segue animation as seen in Secret where it bounces on the bottom of the screen. I have searched the internet but can't find anything to help me.
I am looking for the segue animation to dropdown from the top and bounce on the bottom of the screen.
Currently I have this but it doesn't bounce.
- (void)perform {
UIViewController *srcViewController = (UIViewController *) self.sourceViewController;
UIViewController *destViewController = (UIViewController *) self.destinationViewController;
CATransition *transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromBottom;
[srcViewController.view.window.layer addAnimation:transition forKey:nil];
[srcViewController presentViewController:destViewController animated:NO completion:nil];
}
If it helps I use the POP animation engine.
You need a custom transition using UIKit Dynamics to perform the animation.

Storyboard Custom-Segue tranition for dismissing a UIViewController

I am trying to implement a 'Cover Horizontal' transition for my Storyboard's UIViewControllers. A simple slide right to left and back again. First I am surprised that this is not an option in Interface Builder. Doesn't everybody need this or am I missing something?
I created a Custom-Segue and added a Sliding Transition.
#import "SlideLeftCustomSegue.h"
#implementation SlideLeftCustomSegue
- (void)perform{
UIViewController *srcViewController = (UIViewController *) self.sourceViewController;
UIViewController *destViewController = (UIViewController *) self.destinationViewController;
CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[srcViewController.view.window.layer addAnimation:transition forKey:nil];
[srcViewController presentViewController:destViewController animated:NO completion:nil];
}
#end
That all works fine in the push direction but how do I get the same effect for the dismiss? It all seems a bit difficult for a very simple transition. Again I feel I am missing something.....
Any help would be great.

Showing pushviewcontroller animation look like presentModalViewController

Is it possible to show pushViewController animation look like presentModalViewController but that has background functionality of pushViewController?
If you want to a fade animation, this approach works.
CATransition* transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:gridController animated:NO];
Try this :
UIViewController *yourViewController = [[UIViewController alloc]init];
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController: yourViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
For display PushViewConttroler animation as Present below code is working,
For Push
ViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
CATransition* transition = [CATransition animation];
transition.duration = 0.4f;
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[self.navigationController pushViewController:VC animated:NO];
And for POP
CATransition* transition = [CATransition animation];
transition.duration = 0.4f;
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];
There is 1 issue though, that its display light black background when its going up/down,
Working on that, As soon as its done post new code here.
For All Trying in Xamarin (C#) equivalent Code
From Answer by #hardik Thakkar above, Has the issue of Black backgound during animation, rest all good.
For POP
CATransition transition = CATransition.CreateAnimation();
transition.Duration = 0.4;
transition.Type = CAAnimation.TransitionReveal;
transition.Subtype = CAAnimation.TransitionFromTop;
this.NavigationController.View.Layer.AddAnimation(transition, nameof(CATransition));
For Push
CATransition transition = CATransition.CreateAnimation();
transition.Duration = 0.4;
transition.Type = CAAnimation.TransitionReveal;
transition.Subtype = CAAnimation.TransitionFromBottom;
this.NavigationController.View.Layer.AddAnimation(transition, nameof(CATransition));
You should consider doing something like:
ViewController *myVC = [[ViewController alloc] initWithFrame:OFF_SCREEN];
[navigationController pushViewController:myVC animated:NO];
where OFF_SCREEN is some CGRect below the screen, like (0, 481, 320, 480). Then use an animation block to adjust the viewcontroller's view's frame.origin to be (0, 0). You would probably want to do the animate block in viewDidLoad or viewDidAppear.

Resources