CollectionView didSelectItemAtIndexPath not called if UIView animation is running on the cells - objective-c

I have a collection view displaying incoming calls. With each entry, the new cell starts animating and it should stop once the necessary action is taken on the call. However, did select method doesn't get triggered while this UIView animation on repeat is playing. Any ideas on how to go ahead with this? Thank you.

I figured out the solution. I had forgotten to add UIViewAnimationOptionAllowUserInteraction on the UIView animation options! In case someone else would have the same problem as me, here is my solution!
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{
weakSelf.view.backgroundColor = //;
}
completion:^(BOOL finished) {
}];

Related

Show image/animation above WKWebView

I would like to display an image as an animation that will just glance to the screen and then disappear after 1 or 2 seconds.
It should be a layout above my already existing WKWebView.
I was looking everywhere how to do it but couldn’t configure it out.
Thanks in advance!
In your viewController scene in storyboard, add a UIImageView on top of everything and attach your IBOutlets (or through code in viewDidLoad) and load your image. For example your UIImageView *splashImageView.
Then use this code in your viewDidAppear method:
[UIView animateWithDuration:1.0f // this is a duration param
options: UIViewAnimationCurveEaseOut
animations:^{
[self.splashImagaView setAlpha:0.0f];
}
completion:^(BOOL finished){
}];
For more details read here
Hope this helps.

Terminate a UIView transition animation

I am slowly animating a UIImageView from one image to another. Like so:
[UIView transitionWithView:self.backgroundView duration:30 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.backgroundView.image = endImage;
} completion:nil];
Is there some way to terminate the animation partway through, in response to an event?
A certain Tim Oliver tells me this is how you do it:
[self.backgroundView.layer removeAllAnimations];
You can also retrieve the frame the animation ended on using self.layer.presentationLayer.frame, if you need to freeze the view in the partially animated state.

no animation when using modal segue

I have a view controller and have a few objects that I have some simply animations hooked up to.
[UIView animateWithDuration:0.25
delay: 10.1
options: UIViewAnimationOptionCurveEaseIn
animations:^{
addNameViewConstraint.constant = 10;
addNameView.alpha = 1.0;
[self.view layoutIfNeeded]; // move
}
completion:nil];
[UIView animateWithDuration:0.25
delay: 0.15
options: UIViewAnimationOptionCurveEaseIn
animations:^{
addEmailViewConstraint.constant = 10;
addEmailView.alpha = 1.0;
[self.view layoutIfNeeded]; // move
}
completion:nil];
When I was using the push segue the animation works fine. But when I switched to using a modal segue the animation stopped working. I increased the delay in the first one to 10.2 seconds thinking that maybe it was animating before I got to see it. I am calling this animation in the viewWillAppear method. Again works if I'm doing a push segue.. but not for modal. Any ideas?
I am calling this animation in the viewWillAppear method
This is a common mistake. viewWillAppear: is too soon to start the animation. The view has not yet appeared so there is nothing to animate. Move the animateWithDuration:... code to viewDidAppear: and all will be well.
This is, however, as you say in your comment, insufficiently satisfying. What you are after is that the modal transition should be happening and your extra animations within the new view should already be happening as the modal view is in the process of appearing. Instead, with viewDidAppear:, the modal view finishes appearing, it settles into place, and then your other animations start, which is not as cool.
One solution might be to move the animations again, this time to viewWillLayoutSubviews. This is trickier because this method gets called a lot. You will need to use a BOOL instance variable as a flag to ensure that your animations run only once. Thus, this should work (I tried it and it seemed fine):
-(void)viewWillLayoutSubviews {
if (!self->didLayout) {
self->didLayout = YES;
[UIView animateWithDuration:0.25 animations:^{
// mess with constraint constants here
[self.subv layoutIfNeeded];
}];
}
}

Detect end of implicit animation when changing the UICollectionViewLayout

I am currently working with UICollectionView and after changing the layout from one to another with setCollectionViewLayout:animated: I want to execute some code upon the completion of the animation. Any idea how to achieve that?
Cheers,
Just for the record, there is now a -setCollectionViewLayout:animated:completion: method on UICollectionView, introduced in iOS 7.
I found that to be able to control the animation, rather than using the implicit one with setCollectionViewLayout:animated: you can use a standard UIView animationWithDuration and change the layout in the animations block, like this:
[UIView animateWithDuration:0.4
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
self.oldView.collectionViewLayout = self.otherLayout;
self.newView.alpha = 1.0;
}
completion:^(BOOL finished){
self.oldView.alpha = 0.0;
self.otherLayout = nil;
}];
I don't know if it is the recommended way to do it but it lets you control the animation and execute code upon completion.

Why does view draw under the task bar after a custom scale and flip animation?

Same code as in a previous question, but a different issue.
I've created a custom animation to add a view controller to a UINavigationController. This code scales a view to 80% the original size, then flips it, then scales it back up to its original size:
[UIView animateWithDuration:scaleDuration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
// Scale the controllers' views down.
self.view.transform = CGAffineTransformScale(self.view.transform, 0.8, 0.8);
} completion:^(BOOL finished) {
// Transition to the new view and push on the new view controller.
[UIView transitionWithView:self.view duration:1 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[self pushViewController:viewController animated:NO];
} completion:^(BOOL finished) {
[UIView animateWithDuration:scaleDuration delay:0 options:UIViewAnimationOptionCurveLinear animations:
^{
// Scale back to the original size.
self.view.transform = CGAffineTransformScale(self.view.transform, 1.25, 1.25);
} completion:nil];
}];
}];
The issue is that, when the animation completes, the new view is displayed very nicely, except that it is drawn under the task bar. That is, it draws in at screen origin 0,0, rather than 0,20. The "Status Bar" option is set in IB (to "Black"), and, naturally, this does not happen if I use a standard UINavigationController push animation, only my custom one. If I rotate the device after the animation, the redraw on rotation moves it to the proper place. But how do I get it to do that in the first place?
As an added wrinkle, it does not draw under the task bar if I move the pushViewController:animated: call a line down to the completion: block (though then the view appears to flip to itself and then suddenly show the new view, of course).
I found the only work around so far is hide the navigationbar and then show it.
after you set your transform, add following 2 lines:
[self setNavigationBarHidden:YES];
[self setNavigationBarHidden:NO];
It's ugly but works, I am also looking for a better solution.
note: layoutsubview, setNeedsLayout won't work.