How to flip two views Objective C iOS 13 - objective-c

I have two views that flip (like Turing over a card horizontally). iOS 13 has depreciated the begin animations code and I'm trying to figure out how to use [UIView animateWithDuration:delay:options:animations:completion:]
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.ABCard cache:YES];
[self.ABCard exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
I'm trying to do the following but the animation just switches views instantly with no flip action.
[UIView animateWithDuration:1.0 delay:1.0
options: UIViewAnimationCurveEaseInOut | UIViewAnimationTransitionFlipFromLeft
animations:^{
[self.ABCard exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
} completion:^(BOOL finished){
}];

exchangeSubviewAtIndex doesn't change the look of the animation so it's won't result in an animation, which is why you just see it flip.
Results from this answer may help you with a proper solution: iPhone Flip Animation using UIViewAnimationTransitionFlipFromLeft in landscape mode

Related

I want to slide a transparent menu in from the left

I would like to implement a menu as shown above. I'm a total iOS newbie. I've been searching for that kind of control since couple of days.
Can someone guide me step by step, from scratch?
You can implement the above in following steps :-
1>Left Menu view is a UIView added as a subview with various cutom UIButtons over it added as subview.
2>Initially you have to set the frame so that only a particular part of the view is shown(Panel Part).
3> On the click of indicator button , expand the frame to its full to show the buttons.
4>On next click i.e(odd clicks) collase the frame.
Above animation can be achieved using simple UIView Animation.
Sample code(Original frame width=300,Height 300) :-
yourMenuView.frame=CGRectMake(0,10,100,300);
[yourViewController addSubview:yourMenuView];
-(IBAction)expandMenu:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
CGRect frame=yourMenuView.frame;
frame.size.width+=200;
yourMenuView.frame=frame;
[myview removeFromSuperview];
[UIView commitAnimations];
}
-(IBAction)collapseMenu:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
CGRect frame=yourMenuView.frame;
frame.size.width-=200;
yourMenuView.frame=frame;
[myview removeFromSuperview];
[UIView commitAnimations];
}

Can I horizontal filp the UIButton?

I've some problem with UIButton.
In my case I have to flip the button horizontally.
I tried it's width to minus value. But it doesn't work.
How can I do this?
Simply set its transform to CGAffineTransformMakeScale(-1.0, 1.0).
If you want it to rotate 360 degrees horizontally:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75]; // transition speed
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.YourButton cache:NO];
[UIView commitAnimations];

How to stop executing FOR loop until code is completed

I made this thing. It has no purpose other than for demonstration to myself. Essentially, I'm moving a view that I created around the screen in a loop. The problem is that it doesn't wait until it's done with one animation before starting the other, and so the view bypasses the first two and ends up at the last toastRect after the for loop is done, and it doesn't keep moving after that. How can I force the code to complete each animation before moving on to the next?
int i;
for (i=0; i < 100; i++) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:9];
toast.view.frame = toastRect1;
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:9];
toast.view.frame = toastRect2;
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:9];
toast.view.frame = toastRect;
[UIView commitAnimations];
NSLog(#"%d",i);
}
}
I think you need to use + (void)setAnimationDidStopSelector:(SEL)selector. Take a closer look at http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html if you want.
You can use the setAnimationDidStopSelector method to chain the animations. Check the docs for details: http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html%23//apple_ref/occ/clm/UIView/setAnimationDidStopSelector:

How to let two animations for UIView executed one by one

I have a small UIView and want to let it move to center of screen first, and then, zoom to full screen.
But when I begin start an animation like
[UIView beginAnimations:#"animation1" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(showDetailToFullscreen)];
self.currentDetailVC.frame = centerFrame;
[UIView commitAnimations];
And in the same controller, I have a method:showDetailToFullscreen
- (void)showDetailToFullscreen {
CGRect screenFrame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
[UIView beginAnimations:#"animation2" context:nil];
[UIView setAnimationDuration:0.5];
self.currentDetailVC.view.frame = screenFrame;
[UIView commitAnimations];
}
but when start, it still executed together.
I think the problem they are still in the same transaction. But how can I let these two animation executed one by one? Appreciate for any answer!
Try this instead of the setAnimationDidStopSelector:
[self performSelector:#selector(showDetailToFullscreen) withObject:nil afterDelay:0.5];
It's now considered much better to annimate views using the 'blocks' methods that can be found in the "Animating Views with Blocks" section in the UIView Class Reference.
In most of these methods you can specify a "completion" block of code that can be used to start off a second animation when the first animation completes. You could also call showDetailToFullscreen within this completion block.
I'd reccommend trying this method instead.
Are you targetting iOS 4 or later? If so, I recommend using the block-based animation methods instead. What you want to do is very easy:
Example from UIView docs:
[UIView animateWithDuration:0.2
animations:^{view.alpha = 0.0;}
completion:^(BOOL finished){ [view removeFromSuperview]; }];

i can't apply curl animation on image

How to apply curl animation on Image.( i want animation like Books page turn from left to right or vice versa. so anyone know about it please help me for this.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[oldView removeFromSuperview];
[UIView commitAnimations];
This thread may be a valuable resource:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/18548-pagecurl-animation-os-3-0-a.html