Animate leafing through? - iphone

Is there any way to animate leafing through views to look like a real book leafing through?

There is always the option of using CoreAnimation to animate any view. For this purpose, it could become quite complex though.
There is a native animation for UIView that peels it up from the corner like a page. This kind of animation is more akin to leafing through a notepad than a book but it may just serve the purpose your looking for. If you wanted to do this it would look something like this:
[UIView setAnimationDuration:duration];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:view cache:NO];
[UIView commitAnimations];
The duration of the animation can be set to whatever you like.

Related

iPhone UIView animation

Grettings to you...
i want to paginate when the user swipe on the left or right side of the uiview
i am able to detect the swipes using UISwipeGestureRecognizer.
now what i am trying to do is when the user is swiping i want to give slide animation.
currently i have the below code
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft, forView:[self cardView] cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
this gives me the flip effect when i swipe on the view.
Please provide me some example or links to try the slide effect when swipe on the view.
Many Thanks!
You're going to want to use a UIScrollView, not a straight UIView. This has support for swipes and paging. Here's a nice tutorial to get you started. Good luck!

How can we turn views like turning a page in an iphone application?

Is it possible to turn a view slowly like turning a page? When i swipe from right to left, the current view will turn and the next view will be shown. And from left to right, the previous view will come slowly as we move the finger.
How can I do it? Any ideas??
You should add and remove subviews from your view by detecting the touch movements, using the animation transtion styles:
UIViewAnimationTransitionCurlUp //for removing views (vice-versa)
UIViewAnimationTransitionCurlDown // for adding views (vice-versa)
like:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO];
[self.view addSubview:nextView];
[UIView commitAnimations];
You should customize above according to ur needs.
Hope this helps.
Thanks,
Madhup

UIView Animation: Shrink

I'm looking to have my main view shrink to reveal the next view in the same way the Facebook app's views shrink when you press the top-left button. I already have it working with one of the included animations like this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[self.navigationController popToRootViewControllerAnimated:YES];
[UIView commitAnimations];
However, since "Shrink" isn't one of the included animations, I'm a bit stuck. How could I make this shrink instead?
I'm fairly well-experienced with the iPhone SDK but haven't spent a lot of time with UIView animations.
Have you tried combining a scaling and translating transformation?
UIView's setAnimationTransition: method makes the packaged set of animations dirt simple, but if you want to do something else, you have to drop down a level and use Core Animation itself.
It isn't too bad: basically you use CATransaction's begin and commit methods and in between, get the view's layer and set its transform property directly. To shrink it you could set the scale to 0.00001, causing it to shrink.
Instead of removing the view right away, you will have to set a completion block and remove it yourself when the animation is done. And you might want to reset the transform back to normal, if you plan to use the view again.

Animating UIView problem (matching the expanding animation to the shrinking animation)

I'm trying to animate a UIView so that it can grow larger when tapping a button and shrinks down to its original size by tapping the button again.
I do this by adjusting frame to its new size and origin and running the code below.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.theView.frame = frame;
[UIView commitAnimations];
When animating to a bigger size the animation is how it should be. But when animating to its original size (smaller) the view is re-sized instantly and then animated to its designated location.
What I need is that the resizing to the smaller frame is animated as well.
I've tried adjusting the autoresizingMask as well, but that didn't change anything.
Hope someone can help.
thanks.
Michiel, Raj,
I made a youtube tutorial showing how to make views expand and shrink like in the facebook iPhone app.
Hope it can be of some help: How to make expanding/shrinking views on iPhone SDK
Adam
Try this
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationRepeatAutoreverses:YES];
self.theView.frame = frame;
[UIView commitAnimations];
In response to comment;
If you want to control animation reverse, have a flag like BOOL isbig and set it in app launch to NO, then toggle it in every button tap, then check it if it is YES or NO, and according to the result call a method. If NO, call your code, if not call the code again but this time set the frame to the original size.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.theView.frame = originalFrame;
[UIView commitAnimations];
I could solve the problem by suggestion found in other thread, it has its own limitations though. I have posted the code in the same thread where the solution was suggested:
UIView scaling during animation
I worked around this problem when releasing my app by just removing the animation.
It kept bugging me in the back of my mind, so just this week I thought that maybe by using the center property and the size instead of the origin it would make a difference.
So I decided to test this out. Guess what. The problem doesn't occur when using sdk 4.x
Thanks all for trying to help me out.

Flipping UIView inside UIScrollView

In photo app of iphone you can see smooth scrolling to the other picture with finger flicking. Is it possible to allow individual view to be 'flipped' (or rotated) to show its back side ? Found that UIScrollView is used for smooth scrolling and found the code for flipping UI. Outside of UISCrollView I got the flip to work using the code below. But once inside UIScrollView this doesn't work - it executes but UI never switches.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[UIView setAnimationDuration:1.0];
[myView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
Perhaps this is not suppose to work this way. What is the recommended way or technique to have flippable individual views inside the UIScrollView ?
Never mind. It does work. Once inside UIScrollView there were several UIViews and I needed to make sure I grab the pointer to current UIView. The above code works in this case as well. I was doing a flip on a view which was hidden :)