Having a puzzling problem. I have a universal app with a lot of shared code between the iPad and iPhone versions. There are different layouts in the nibs but essentially the same views and view hierarchy - one UIView used as a container for two sibling UITextViews.
UIView mainView with children:
UITextView passageTextView
UITextView notesTextView
One UITextView is hidden, the other visible.
The following is my code. The section commented out was my original animation attempt. This worked just as desired on the iPad, but not on the iPhone. The uncommented section is take 2, using the method recommended in the docs. The uncommented code does not work on either the iPad or iPhone - it hides/unhides my views but without any animation. If I add code to the completion block that also gets executed, so it's doing something, just not animating.
/*
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mainView cache:YES];
passageTextView.hidden = YES;
notesTextView.hidden = NO;
[UIView commitAnimations];
*/
UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationTransitionFlipFromRight;
[UIView transitionWithView:mainView
duration:1.0
options:options
animations:^{ passageTextView.hidden = YES; notesTextView.hidden = NO; }
completion:NULL];
Edit: Still working on the problem, hoping someone has a suggestion.
Additional update
Figured out why the following was not working in the iPhone:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mainView cache:YES];
passageTextView.hidden = YES;
notesTextView.hidden = NO;
[UIView commitAnimations];
I had neglected to wire the view to mainView in Interface Builder. Hours debugging and I just now thought to check that.
But, I still do not know why animation blocks are not working for either the iPhone or iPad. I have tried several approaches but I'm not getting any animation even though the show/hides are working.
I think you are using the wrong animation option.
Replace your second animation option by UIViewAnimationOptionTransitionFlipFromLeft (note the Option between Animation and Transition)
I believe that UIViewAnimationTransitionFlipFromLeft (which is what you have in your code) is a UIViewAnimationTransition not a UIViewAnimationOptions.
Related
I tried to find a solution for it for a while now.
I have a XIB called CameraViewController.xib. I have a few animations in it. (Alpha, Scale, Transition) I use AutoLayout and Interface Builder, xCode 6 and Objective C. (iPhone)
Every animation worked fine until 2 weeks ago they just stopped working. I can´t figure out why. Every animation is ignored and jumps directly to endstate.
It´s just in this XIB in all other XIBs and my Storyboards ViewControllers every animation is working fine.
There is no Error. I tried all possible forms of animating down to CoreAnimations but they all jump to endstate.
The XIB is complex and it has a lot of code in it. I don´t want to build the XIB again trying and trying until I find the mistake.
Anybody got the same problem or an idea ? Or a link for me where I can find out why animations aborting and jumping ?
This is driving me crazy...
EDIT :
[UIView animateWithDuration:0.5f
animations:^{
liveLabel.alpha = 0.7;
liveRedDot.alpha = 1.0;
}
completion:^(BOOL finished){
nil;
}];
CABasicAnimation *morph = [CABasicAnimation animationWithKeyPath:#"cornerRadius"];
morph.fromValue = #0;
morph.toValue = #37.5;
morph.duration = 0.5;
[playStopButton.layer addAnimation:morph forKey:#"morph"];
I also tried different code snippets for the same animation but not a single one is working. As I said same code is working in other XIBs or ViewControllers of my StoryBoard :
[UIView animateWithDuration:0.5 animations:^{
playStopButton.transform = CGAffineTransformMakeScale(0.6,0.6);
playStopButton.backgroundColor = UIColorFromRGBWithAlpha(0x000000,0.3);
}];
[UIView beginAnimations:#"button" context:nil];
[UIView setAnimationDuration:0.5];
playStopButton.transform = CGAffineTransformMakeScale(0.6,0.6);
playStopButton.backgroundColor = UIColorFromRGBWithAlpha(0x000000,0.3);
[UIView commitAnimations];
[UIView
animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
playStopButton.transform = CGAffineTransformMakeScale(0.6, 0.6);
}
completion:nil];
I am working on a storybook app, i want to do the page curl like in the following video.
Demo Video
Can anyone tell me how to do exactly like this.
Update:
I want this page curling to support iOS 4.3+. UIPageViewController will work only on iOS 6.
You might want to consider UIPageViewController. It is quite useful in creating apps which use page curling animations. Here is the documentations link.
You can make use of the UIView's animation effect for this. I guess this should help you
[UIView beginAnimations:#"Curl" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:contentView cache:YES];
[UIView commitAnimations];
where the contentView is the view where you are applying the animation. By varying the duration and animation curve you can modify your animation effect.
There are two ways of doing it:
The hard way, implement everything yourself (from scratch, with layers and masks and transforms and gradients) and a lot of headache.
the Easy way, read the documentation for UIPageViewController as suggested by #Zen. Its very useful and gives you the exact animation that you want (as shown in video). Or, using some third party code.
If you dont't have time constraint, then I will say, go the first way. You will learn a lot.
Cheers, have fun :)
EDIT
Here is the link to a sample app:
https://www.dropbox.com/s/x4qo2igrzvnkj16/CurlAnimationProject.zip
check it and tell me what you think.
SettingViewController *svc = [[SettingViewController alloc]initWithNibName:#"SettingViewController" bundle:nil];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[self.navigationController pushViewController:svc animated:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
As mentioned several time in the answers the UIPageViewController (apple documentation) is the thing you should be looking at.
The implementation is fairly straightforward, the controller uses 2 delegates
datasource : controlling the content to display (your pages) through 2 main methods
delegate : controlling its behaviour
It implements the swipe gesture for scrolling from page to page and can feature a page control at the bottom of your view.
For transitioning from page to page, you can either set a scroll animation (nice for photo / portfolios type) or the page curl you are looking for.
You can make page curl/flip effect by
For landscape mode:
[UIView beginAnimations:#"Curl" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:contentView cache:YES];
[UIView commitAnimations];
For portrait mode:
[UIView beginAnimations:#"Curl" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlLeft forView:contentView cache:YES];
[UIView commitAnimations];
I have a custom UIView. It initializes two rectangular UIBezierPaths, and in drawRect it simply fills these two paths.
This view is placed on a button. When the button is clicked, a rotation is applied to it inside an animateWithDuration block:
icon.transform = CGAffineTransformMakeRotation(M_PI*-0.25);
This works great.
When the button is clicked again, I am trying to make the view rotate back to it's original orientation (reverse the rotation). I have tried:
icon.transform = CGAffineTransformInvert(icon.transform);
icon.transform = CGAffineTransformMakeRotation(M_PI*0.25);
icon.transform = CGAffineTransformIdentity;
... and a number of other variations, but none of them seem to work. Instead, the view is distorted until it's no longer visible -- sorta stretched to nothing. Sometimes, reapplying the first transform brings it back but with other reversals it doesn't.
What am I doing wrong?
In ios the transform is always relative, so once transformation is done, the next transformation should be relative to the previous transformation. You can simply change the frame of the view and revert it back to normal on second button click. On even clicks you will have to revert back the frame. Implement the following code. You can use the block level code if you feel comfortable with it as it is the new norm.
int noOfClicks = 0;
-(IBAction)yourBtnAction:(id)sender
{
noOfClicks++;
if(noOfClicks %2 != 0)
{
[UIView beginAnimations:#"Rotate" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
CGRect frame=yourView.frame;
frame.origin.y+=20;
yourview.frame=frame;
[UIView commitAnimations];
}
else
{
[UIView beginAnimations:#"Rotate" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
CGRect frame=yourView.frame;
frame.origin.y-=20;
yourview.frame=frame;
[UIView commitAnimations];
}
}
If you don't want to make so many change you can use following to revert back but employing same logic:
[UIView beginAnimations:#"Rotate back" context:nil];
[UIView setAnimationDuration:1.0];
yourView.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
I have this code:
- (IBAction)open:(id)sender{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[splash removeFromSuperview];
[UIView commitAnimations];
}
I have an imageView "splash" and I remove it with the IBAction, but my problem is that it remove splash from left, and I want to remove it from right, what can I do?
There is no UIViewAnimationTransitionCurlRight nor Left in the iOS.
For IOS5 projects you can use the new UIPageViewController that is working similar to the iBooks App.
you can see my answer here with links - Page curl - Leaves Project - Interaction elements
For other versions you can find here a work around to set this curl:
I want to use animation to imageview using UIanimationtransitioncurl right or left. Is it possible?
Good Luck
I use a UIView animation to randomly animate 5 squares (UIButtons) around the screen. Depending on a user selection, there are anywhere from 2 to 5 squares visible. When only 2 are visible, the other three's hidden values get set to YES, so they are actually still animating (right?), they just aren't visible. But when only 2 are visible, the animation is smooth, but when all five are visible, the animation gets choppy. I'm not really sure how to describe it, because the squares are still moving at the correct speed and moving to the correct points; the choppiness isn't terrible, just bad enough to be noticeable. Is there any way to get rid of it? This is the code I use to animate the squares:
Edit: changed animations to block:
[UIView animateWithDuration:animationSpeed
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
view.center = destPoint;
}
completion:^(BOOL finished){
if([view isEqual:squareThree])
[self moveBadGuys];
}
];
/*for(UIButton* button in squareArray) {
if(!shouldMove)
return;
[UIView beginAnimations:#"b" context:nil];
[UIView setAnimationDuration:animationSpeed];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
view.center = destPoint;
[UIView commitAnimations];
}*/
Edit: the view presenting this is the third in a stack of three UIViewController presented with
ViewController* controller = [[[ViewController alloc] init] autorelease];
[self presentModalViewController:controller animated:NO];
Does this way of presenting views eat up memory?
There are a few things that can cause this. It always comes down to how complex the content is. Also, simulator can be really bad about handling animation, so be sure you are testing on real hardware.
Are there large images on the buttons? Are the buttons casting shadows? Those things can slow it down.
Also- use block based animation. Not the old begin-commit methods.
Not exactly sure why it's slow, but have you tried nesting the thing differently?
if(!shouldMove)
return;
[UIView beginAnimations:#"b" context:nil];
[UIView setAnimationDuration:animationSpeed];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
for(UIButton* button in squareArray) {
view.center = destPoint;
}
[UIView commitAnimations];
does (almost - the logic is a bit different in the !shouldMove case, but that's a different story) the same, but in a cleaner way.