How to implement flip transition effect for UIView as like in "flipboard" application. here i already have sample which will make flip from left to right or right to left. But here i want to implement fold flip from bottom to top or top to bottom.
you can use the below line of codes for this kind of animations
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5];
[UIView transitionFromView:view2 toView:view1 duration:3 options:UIViewAnimationOptionTransitionFlipFromBottom completion:NULL];
[UIView commitAnimations];
u can set the duration and animation transition as per the requirement.. was working only in ios5..
check this tutorial: http://www.gethugames.in/blog/2012/02/extended-epgltransitionview.html
and this project: https://github.com/saiy2k/EPGLTransitionView
PS: Its my own blog and link to my fork of EPGLTransitionView
Here's a concept of how I would try to approach the problem. Maybe I'll try to implement it in free time to have a sample handy.
The moment you start the animation, make a snapshot of current UIView by reading its graphics context into a bitmap
Create three (yeah, three -- bear with me_) UIViews with sizes so that they make up for two halves of the view to be flipped, with two views for area of the right half
Draw half of the bitmap on the left view (first one), right half on the right view (second one), in their respective drawRect: implementations
Hide the original view
Create the next view we want to transition to
get its contents into a bitmap as well
hide the next view
make the third temporary UIView to draw the right half of the image (third one)
position the third one under the second one
Animate half of the flip of the second one along its left edge
make the second one display left half of the next view
Make the rest of the flip animation
After having done the transition, show the next view, hide all temporary views
Et voilla! At least I hope.
I think that instead of those three UIViews you could use one UIView with three CALayers instead.
And there's an issue of doing the transition interactively, with the user sliding his finger over the pages.
I also I think there's an issue of the flipping view to have a two-sided layer. Haven't had the opportunity to play with those properties and what they can help to achieve.
Another solution would be to create a texture from UIView's contents and put up an OpenGL surface over it (alpha-transparent CAEAGLLayer-based one of course). Then what you'll do with the triangles that are textured with that image is only limited by your imagination. I guess that would also allow to create a Genie-like move-to-trash animation that Mail iOS app uses.
Edit: Oh, sorry, I was thinking of a right-to-left flipboard-style flip, not top-to-bottom, but overall idea is the same of course.
Related
I have a view that slides up from the bottom of the screen when the user swipes up and when this happen a little arrow is supposed to rotate so that it is now pointing downwards. In a similar fashion, when the view is slid away to the bottom of the screen, the arrow should rotate again so that it points upwards. Ideally, I would like to call the same method every time the view slides in or out to rotate the arrow 180 degrees. Right now I am using:
[UIView animateWithDuration:.5 animations:^{
viewToBeRotated.transform = CGAffineTransformMakeRotation(M_PI);
}];
This works fine the first time but then doesn't do anything on further method calls, any pointers on how to do do this correctly?
When you set a transform on a view you erase previous transform.
To have multiple transforms applied to one view at the same time you must "add" them. Each CGAffineTransformMake{Rotation/Scale/etc} has an equivalent which allows you to "add" a transform to another one.
To resolve your issue you can use the following :
self.iv.transform = CGAffineTransformRotate(self.iv.transform, M_PI);
As a small project to get myself used to some more iPhone elements I've decided to create a sample in call screen, modeling it on the native iPhone call screen (IOS 4)
However I'm struggling to make out what elements the native in call screen uses to make up the view that is displayed.
I was wondering if someone with more experience on iPhone could help me out by explaining what the various elements are?
Is the bottom part a UIActionSheet that is slightly transparent and with a UIBUtton placed over it? Or is it a slightly transparent imageview with the button over-layed?
Similarly at the top, it looks like its an imageiew with the name or number of the callee/caller and the call duration underneath, would I be correct in thinking that?
The part I'm really interested in is the bit where the icons are held in some sort of dialog in the centre of the screen that is animated to swing around to a keypad when it is selected, is this some sort of iPhone control that I can use or customise?
EDIT:
I've tried two things to try to achieve this so far:
1) I've created a view within a view and I am trying to flip this however I can only seem to get the main view to flip properly and not the view inside it which is the one I want and it doesn't seem to be a good approach.
2) I've tried to look at using the Utility application approach to it but again this seems to be for flipping the full screen and not just a section within a screen (view)
Has anybody got any pointers on what to try next? Or if one of the above methods is the ideal way to do it and should be investigated further?
At a basic level, I would say that the panel of 6 buttons is simply a view with 6 buttons laid out in it as subviews.
The rounded corners and border stroke can be achieved by accessing the view's layer property and the layer's properties for cornerRadius, borderWidth, and borderColor, e.g.
view.layer.cornerRadius = 10;
view.layer.borderWidth = 2;
view.layer.borderColor = [UIColor whiteColor].CGColor;
This requires including the CoreGraphics Framework, and the appropriate header files in your code.
I notice there's a gradient (or it appears to be a gradient) in the border stroke. I am not sure how to achieve that without doing something more involved and clever (such as a containing view that is just slightly larger veritically and horizontally than the view containing the buttons and is filled with a gradient color. The result would be a gradient border, but this doesn't seem like the best way to do that...
The flip is actually pretty easy. You can create a UIView animation with something like this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:view cache:NO]
[UIView commitAnimations];
Does this help, or at least get you started?
I've added some UIImageViews with png images to my view, using interface builder. Initially they are added off-screen.
Later, I animate them onto the screen with CoreAnimation, like so:
[UIView beginAnimations:#"slide" context:nil];
[UIView setAnimationDuration:0.1f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
image.frame = CGRectMake(81+1, 390, 150, 80);
[UIView commitAnimations];
Once they appear onscreen, they look really blurred or fuzzy.
I've heard of this happening before. Does anyone have any idea how to fix it?
Usually this means that you are positioning the views at fractional pixel values (e.g. 100.5). Make sure you round the coordinates of the position.
Quick fix: Re-order the object in the Objects pane on the left, i.e. send backward, then send forward again. Not sure why this happens, but it fixes it for me.
UIImageViews and other views can appear blurry in Interface Builder (and in your iPhone app) if the images are, as camdez suggests, not at rounded pixel locations. Fixing this can be tricky because Interface Builder will only display the numbers in the inspector as integers. However, let's say you have configured the "Origin" widget in the "View" inspector to allow you to specify the X and Y of the center of the view, rather than the top left. If your blurry view is centered at 100,100 and is 35 pixels high, Interface Builder will internally compute the top left corner of the view as (100-35/2) = 82.5 and write it to your XIB file as a decimal.
The quick fix:
Change the "Origin" widget back to the "Top Left" setting. Move the view within the canvas so that the pixel values are changed, and then type the correct values back in. Problem solved!
I have a single UIView for drawing any one of a set of items. That is, my one UIView subclass can be told to draw a square, circle, or triangle for example.
I'd like to have a transition to flip that view so that the UIView draws a different shape at the half way point, so it looks like I'm transitioning to a different view, but really I'm just redrawing the single view at the half way point of the transition.
Is there a way to do this, without resorting to using two different UIViews and swapping them out in the animation block? It would be a bit clumsy for me to rejig what I have to use the swap mechanism.
Ideally all I need is some callback or notification that the animation is at the half way point, and then I can redraw the view with the new shape then.
Thanks for any help!
Even if you did know the midpoint of your flip animation, I don't believe redrawing the content of the view mid-animation would do anything. I think that the contents of the view's layer are cached at the beginning of the animation and don't change as the animation proceeds. Also, your view would end up inverted, left to right, at the end of the animation if you didn't have another view behind it.
If you wish to do this as a custom animation, you could break this into two halves using something like Mike Lee's Lemur Flip implementation that I describe in this answer. After the first half of the animation, you could redraw the view's content and complete the animation, ending up back where you started.
However, to me it seems more clumsy to not switch views in response to the transition. It certainly will take a lot more code to do.
you can try to do smth like this. For example, your animationDuration property is set to 2.0f. so, the half way point is 1 second, so you can use
[self performSelector:#selector(yourCallbackMethod) withObject:nil afterDelay:1.0f];
The only way I know of that you could do this is to re-create the animation using Core Animation and then monitor the animation in the presentationLayer using a timer. There is no KVO available in Core Animation Layers so you have to monitor it explicitly.
In other words, it's probably not worth it. I suggest you think of a different way to solve your problem.
I'm well aware that there are only two available UIView transitions, UIViewAnimationTransitionFlipFromLeft and UIViewAnimationTransitionFlipFromRight. I'm wondering if there is anyway that I can implement / emulate a UIViewAnimationTransitionFlipFromTop or UIViewAnimationTransitionFlipFromBottom.
The only way I can think to do this is by flipping the x axis with the y axis, but I've not seen any information about how to do this. Just setting the coordinates of each axis won't fix the issue as the x-axis till remains the x-axis.
Does anyone have any ideas how this can be accomplished?
You can do this by applying a CATransform3D to your main view's CALayer, with your secondary view's CALayer behind it. In this response, I point to a Mac implementation of this animation by Mike Lee. You should be able to reuse a significant portion of that code to recreate this effect on the iPhone.
Guess you'll have to use a UIView animation block with a 3D rotation transform of 90 degrees, have the Core Animation delegate call you when that's done, swap the view with the new one (3D rotated on the other side) and chain with the last 90 degrees for the new view...
Although its not exactly what you want, there are two built-in animations that you didn't mention: UIViewAnimationTransitionCurlDown and UIViewAnimationTransitionCurlUp.
CurlUp looks like someone is peeling the view from the bottom up to the top, and CurlDown looks like the view is being unrolled down on top of the screen from top to bottom. You should at least give them a look, as they are easy to use.