I have programmed the following animation for an UIImageView which works fine when I load the View:
-(void) viewDidAppear:(BOOL)animated{
[UIView animateWithDuration:2
delay:0
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
hat.transform = CGAffineTransformMakeRotation(0.2);
}completion:nil
];
}
Then I push a new View Controller on top of this view, but when I pop this new view controller, the animation doesn't fire... I've tried placing this animation code in viewDidload and in viewWillAppear but that didn't help... Any thoughts?
is it possible that the UIImage view is getting unloaded? If you haven't already try setting strong/retain property to your UIImageView.
Related
I have a master and detail view controller. I have a button that currently disappears after the push segue to the detail and reappears when the pop segue is called, whether it's the interactive gesture or the back button.
This looks really abrupt and I wanted to fade in the alpha on the button with the pop gesture but I don't see any delegate or datasource methods for UINavigationControllerDelegate that show the progress of the pop gesture. Are there any libraries that help with this?
This can be accomplished with a UIView animation.
The idea is to set the alpha of the button to 0 so that it is invisible and then animate it to a value of 1 to create a fade-in effect.
self.myButton.alpha = 0;
[[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.myButton.alpha = 1;
} completion:^(BOOL finished) {
// Code for completion of animation.
}];
This could be placed in the viewDidAppear: method of your view controller.
This question already has answers here:
Display clearColor UIViewController over UIViewController
(16 answers)
Closed 7 years ago.
I have a UITableViewController, inside my UITableViewCell i have an imageView when the user taps on it, i present it modally using my own custom UIViewControllerContextTransitioning to make a zoom effect on it, it works like a charm the problem is that when the animation completes and i call the
[transitionContext completeTransition:YES];
My UITableView which is now behind my Modal UIViewController is removed form the view hierarchy so i got a black screen behind it
[containerView addSubview:toViewController.view];
[UIView animateWithDuration:duration delay:0.0 usingSpringWithDamping:damping initialSpringVelocity:1.0 / damping options:0 animations:^{
// blablabla animation stuff
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];// this line makes my UITableView removed form the view hierarchy
}];
Here is what i've tried so far :
add in the completion bloc the UITableView
[[UIApplication sharedApplication ].keyWindow insertSubview:fromViewController.view belowSubview:containerView];
But this only works on iOS8 ...
Any ideas how to fix this ? thank you !!
Try to set modalPresentationStyle of the presenting view controller to UIModalPresentationCustom
I have an app with two UIViews in a IB ViewController. Each of these is a container view having two UIImageViews.
I use Core Motion gravity to move these views as the device is tipped. There are also two UIImageViews in the IB view.
I am trying to animate the UIImageViews inside the container views. However, when the animation happens, it takes place immediately instead of taking place over 5 seconds that I specify in the annimation.
I have tried to animate the container view and the UIImageViews but the same thing occurs.
Any ideas?
This is my code
[UIView animateWithDuration:5 delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[self.myView setFrame:0,0,11,23self.myView2 setFrame:0,0,11,23))];
)];
}
completion:^(BOOL finished
This changes the size of the container view Myview and myview2.
Your code is:
[UIView animateWithDuration:5 delay:0
Buw that you want to achieve is:
[UIView animateWithDuration:5 delay:5
Instead of doing self.view = view; like I am currently I want to present this view with animation. It is not an entire view controller but just a view, I am just replacing the current view with this view on a button click.
Is there anyway to do this animated?
Thanks in advance.
Try something like:
UIView *newView = ...;
// new view is added as a subview somewhere
newView.alpha = 0;
[UIView animateWithDuration:1
animations:^{
newView.alpha = 1;
}];
Which will fade the view in. You could also look at animateWithDuration:delay:options:animations:completion: which provides other animation options. Or transitionFromView:toView:duration:options:completion:.
In fading a view controller in from black, I am doing the following within viewDidLoad:
Creating a UIView with a black background;
Giving the UIView an alpha value of 1.0f;
Adding the UIView as a subview of [self view];
Fading the black UIView out via animateWithDuration by changing its alpha value to 0.0f; and
Removing the black UIView from [[self view] subviews]
More often than not, this works as planned. Occasionally, however, I see a glimpse of the view controller I want initially hidden, just before the black UIView is drawn.
Is there a way to avoid this? Is there a better method to place this code in than viewDidLoad?
Many thanks
Yes, add the view in the loadView method and do the actual animation in viewDidLoad or viewDidAppear. Or do as the above commentor said and simply use the view alpha.
I would create the UIView that I want hidden in UIViewController's nib file, then link that to via an IBOutlet
#interface SomeViewController: UIViewController
{
IBOutlet UIView *blackView;
}
then in UIViewController's -(void) viewDidLoad; method, I would do the following
- (void)viewDidLoad
{
[super viewDidLoad];
// Fade the opacity of blackView over 1 second,
// then remove it from the view controller.
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
blackView.layer.opacity = 0;
}
completion:^(BOOL finished) {
// This line prevents the flash
blackView.layer.opacity = 0;
[blackView removeFromSuperview];
}];
}