How to add additional animations in Xcode - ios

I have the following code for my iPhone app in Xcode 4.5:
[UIView transitionWithView:self.view
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.view = self.view;
} completion:NULL];
The code works exactly how I want except for 1 thing. Where I have self.view = self.view; I'd like a brief moment before this line where the view clears or even changes to nothing but a black screen, and then transition into the next loaded self.view. The reason is that some of my screens are very similar and the user might think the view didn't reload.

self.view = self.view can not compose animation
set self.view.alpha to zero then do animations.
self.view.alpha = 0.0f;
[UIView transitionWithView:self.view
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.view.alpha = 1.0f;
} completion:NULL];

Related

Animating the expansion of a UICollectionViewCell's content upon selection

How to animate the expansion of a UICollectionViewCell's content upon selection?
Currently I'm using transition animation on my didSelectItemAtIndexPath for animating a view Which isn’t working smoothly like AppStore card animation.
Here is my current code...
AnimateStaticImageViewController *animateImageVC = [[AnimateStaticImageViewController alloc] init];
animateImageVC.modalPresentationStyle = UIModalPresentationFullScreen;
animateImageVC.modelImage = [UIImage imageNamed:text];
[UIView animateWithDuration:0.7 animations:^{
animateImageVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.3);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.7 animations:^{
animateImageVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.7 animations:^{
animateImageVC.view.transform = CGAffineTransformIdentity;
}];
}];
}];
[self presentViewController:animateImageVC animated:NO completion:nil];
So, I was trying a modal transition animation in my app's home page staticImageCollectionView immediately after clicking the image.
The core animation & transform mechanism didn't work for me as I need something like AppStore's card animation.
Using this library worked after some hassle! Following this...
Setting the library with following steps.
Calling the transitioningDelegate of the animationViewController on didSelectItemAtIndexPath (or prepareForSegue if working with segue-navigation controller).
Calling it within a completion block to ignore flickering & delay issue in view presentation.
AnimatedStaticImageViewController *animateImageVC = [[AnimatedStaticImageViewController alloc] init];
animateImageVC.modalPresentationStyle = UIModalPresentationFullScreen;
animateImageVC.modelImage = [UIImage imageNamed:text];
[UIView animateWithDuration:0.2
animations:^{
animateImageVC.transitioningDelegate = self;
} completion:^(BOOL finished) {
[self.view removeFromSuperview];
[self presentViewController:animateImageVC animated:YES completion:nil];
}];
Be careful when setting imageView which is the main presentation of the animation.
Make sure you declaring the delegate 'RMPZoomTransitionAnimating' & 'RMPZoomTransitionDelegate' methods on both fromViewController and toViewController.

UIView doesn't animate

I want to animate the center of a UIView, and I did this in viewDidLoad:
_test.center = CGPointMake(100.0,100.0);
[UIView animateWithDuration:10.0
delay:5
options:UIViewAnimationOptionCurveLinear
animations:^{_test.center = CGPointMake(100.0,-100.0);}
completion:^(BOOL finished) {
}];
But when I run the code, the center of test view is already at 100,-100. Why it doesn't animate?
Move the code from your viewDidLoad to your viewDidAppear. In viewDidLoad, the UIView has been loaded, but it is not visually present yet.
I guess you are using auto constraints which prevent animating views the way you are doing.
In order to fix this issue try these steps:
First:
Move your code to - (void)viewDidLayoutSubviews.
Second:
Do these steps before and after doing any animation to your view:
- (void)viewDidLayoutSubviews{
_test.translatesAutoresizingMaskIntoConstraints = YES;
_test.center = CGPointMake(100.0,100.0);
[UIView animateWithDuration:10.0
delay:5
options:UIViewAnimationOptionCurveLinear
animations:^{_test.center = CGPointMake(100.0,-100.0);}
completion:^(BOOL finished) {
}];
[_test updateConstraints];
}

Animating UIViewController's frame

I am trying to create an animation. When I click on an image, the view expands the from this frame to the view of the UIViewController to the bounds of whole screen on pushing it on the navigationController and shrinking to the same size while popping it back. I was able to create the pushing animation but unsuccessful in my attempt to create the popping animation.
// Code in the controller which pushes the controller on the stack
self.navigationController.view.center = center;
self.navigationController.view.frame = frame;
self.navigationController.view.transform = CGAffineTransformMakeScale(0.1f, 0.1f);
// Code in the viewDidAppear of controller being pushed to the stack
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.navigationController.view.transform = CGAffineTransformIdentity;
self.navigationController.view.frame = [[UIScreen mainScreen] bounds];
self.navigationController.view.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
}
completion:nil];
This works properly but I tried the following code for pop animation in the viewDidDisappear, where initialFrame is the frame on which I am tapping to open the UIViewController.
// Code for viewDidDisappear
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.view.transform = CGAffineTransformMakeScale(0.1f, 0.1f);
self.view.frame = self.initialFrame;
self.view.center = CGPointMake(self.initialFrame.size.width/2 + self.initialFrame.origin.x, self.initialFrame.size.height/2 + self.initialFrame.origin.y);}
completion:nil];
I am not able to make the pop animation work. Please help me out.

UIView Animation of MPMoviePlayerController view

I have a movie playing successfully in a container view that is managed by
BWCVideoViewController : UIViewController
When I start the movie (which works fine), I fade the movie view in successfully using the following
[self.view addSubview:theMovie.view];
theMovie.view.alpha = 0.0;
[theMovie play];
[self movieFadeIn];
- (void)movieFadeIn
{
[UIView animateWithDuration:3.0
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
theMovie.view.alpha = 1.0f;
}
completion:nil];
}
But for the life of me I cannot fade the movie view out when the movie is either stopped or still playing! It just "flashes" and disappears abruptly:
- (void)movieFadeOut
{
[UIView animateWithDuration:2.5
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
theMovie.view.alpha = 0.1f;
}
completion:nil];
}
I've followed suggestions elsewhere on SO such as here but I'm baffled. Same result in simulator/device (iOS7)
Well I've solved it, but not how I expected to.
I created another subview (so it sits ABOVE the video) with the same frame size. I fade this out/in and get the desired result. weird.

UILabel disappears after animateWithDuration

I've got a UILabel that slides in and out of view, but after it slides back in it disappears. I want it to persist.
How can I achieve this? Also, why does this happen?
Here's the code:
[UIView animateWithDuration:0.1
delay:0.0
options:UIViewAnimationOptionAutoreverse
animations:^{
[self.listLabel setFrame:CGRectMake(325, 141, 320, 181)];
}
completion:nil];
Thanks.
In official documentation
UIViewAnimationOptionAutoreverse
Run the animation backwards and forwards. Must be combined with the UIViewAnimationOptionRepeat option.
Why don't you use UIViewAnimationOptionCurveEaseOut and UIViewAnimationOptionCurveEaseIn animation option for your label?
Just set your label's frame.origin.x = [outside the right side of it's superview's bound]
and set it back to it's original position when you want to slide-In again using EasyOut animation.
Here's something what I'm talking about...
CFRect frame = self.listLabel.frame;
//Point to hide your label by sliding it outside the right side of it's parent's view.
// mask or clipToBounds of parent's view must be YES
frame.origin.x = [self.listLabel.superview.frame.size.width];
[UIView animateWithDuration:0.1
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[self.listLabel setFrame:frame];
}
completion:nil];
And When you want to slide back in, use opposite animation and label's original position, of course you need to store it's original position somewhere so you could slide-in it back.
[UIView animateWithDuration:0.1
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[self.listLabel setFrame:label_original_frame];
}
completion:nil];
UIViewAnimationOptionAutoreverse is designed for a cyclical animation. To just bounce something offscreen and back, you should just write it as 2 animations:
CGRect originalFrame = self.listLabel.frame;
[UIView animateWithDuration:0.05
delay:0.0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
[self.listLabel setFrame:CGRectMake(325, 141, 320, 181)];
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.05
delay:0.0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
[self.listLabel setFrame:originalFrame];
}
completion:nil];
}
];
As there still seems to be no valid answer, I propose a (now possible) approach:
In Xcode 6, with the app running in the simulator, go to "Debug" in the top bar, select "View Debugging" and "Capture View Hierarchy". Then go and search your missing Label. You can also see properties etc. of the Label in the right Xcode bar.

Resources