using the following UIView class method on iPad to animate the swapping of different images inside a UIImageView:
[UIView transitionWithView:self.view
duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^{[imageView setImage:foregroundImage];}
completion:nil];
However, the animation does not seem to be taking notice of the current interface orientation. In other words, "up" is always up relative to Portrait orientation. So, for example, if the device is in Landscape Left orientation, the page curls from left to right (rather than "up"). If I'm in Upside Down orientation, the page curls from top to bottom, etc.
Any idea how I can get it to curl "up" relative to the current interface orientation rather than only curling up relative to Portrait orientation?
I encountered the same problem. I've found a workaround but not sure why your code(the same approach I took) didn't work.
My walk-around is to create a wrapper(UIView) for all UI elements in the page to be purled. I've make the wrapper the only subview of the view controller's view and all other views subview of the wrapper. And modify the target to wrapper as below
[UIView transitionWithView:self.wrapperView
duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^{[imageView setImage:foregroundImage];}
completion:nil];
In your specific case, if you only need 'imageView' to be curled up, you can try set the target to imageView, namely
[UIView transitionWithView:self.imageView
duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^{[imageView setImage:foregroundImage];}
completion:nil];
it worked in my project. So it seems if the animation target is the root view of VC, this problem will occur, otherwise the curling animation works find. Anyone knows why?
Related
I have 2 container view controllers on my main screen, one which acts as a global toolbar at the top. This is great most of the time, but I need to animate this off screen, to give more room for the user to see lots of information on the screen. Is this possible? I've been looking at the documentation, but I'm not sure if I need to use the transformation animation, or change the frame/bounds. Any suggestions would be grateful.
You should just be able to change the frame/bounds in a standard UIView animation (block or otherwise). No need to reference the "contained" views.
Update: Here's a block animation example.
[UIView animateWithDuration:1.0f
animations:^{
view1.frame = CGRectMake(blah...);
}
completion:^(BOOL finished){
// do something here if you wish.
}];
In this post the author said that we could restart animation after switching tab in viewWillAppear.
I called my startAnimation in both viewWillAppear and viewDidAppear, but still failed.
Below is part of my code.
- (void)startAnimation {
[UIView setAnimationsEnabled:YES];
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat
animations:^(void){
self.foreground.transform = CGAffineTransformMakeTranslation(0.0f, 5.0f);
}
completion:nil];
}
The animation works perfectly when first shown by calling startAnimation in viewDidLoad, but it never works after switching to other tabs.
Neither does it work after the application restarts from the background, even if I've registered an observer of UIApplicationWillEnterForegroundNotification for startAnimation.
Please help me, I'm new to iOS development, thanks very much.
The method viewDidLoad only gets called when your view controller is first loaded.
If you want your animation to run when you return from other view controllers to this one, you should call the animation method in viewWillAppear, not viewDidLoad.
To make the animation go back to it's previous value and then animate again, you would first set your view's transform to identity (setting it to the starting point) and then invoke your animationWithDuration method.
You might find it easier to animate your view's frame.origin or center property rather than changing the transform. Changing the transform gets complicated when you combine translations with rotations, scale changes, etc. Also, the frame property is no longer valid when the transform property is not == the identity transform.
I am thinking of adding a animation to my Table View. This should work as following: The User swipes over a table view Cell horizontal and the content of the cell turns, so that "the other side of the card" is visible. How could i do that? I have no idea if I e.g. try to do that by making everything by myself with a opengl view in every row, or if i could use CoreAnimation? Are there maybe better ways to do that? How do the professionals realize such animations (e.g. Flipboard)? I don't need source code, a short description or a keyword would help very much!
Apple has build in functionality. I am currently using it and it works great.
Let's say you have 2 views A and B that you want to flip between. The flip animates the entire area of the parent, so if you only want the flip to be all of A, make sure A and its parent are the same size.
Here is what I like to do to flip back and forth:
if(B.superview == nil)
[UIView transitionFromView:A toView:B duration:1.f options:UIViewAnimationOptionTransitionFlipFromRight completion:nil];
else
[UIView transitionFromView:B toView:A duration:1.f options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
After the flip, the FromView will be removed from its parent (superview) and the ToView will be added to that parent. You can put the above code in a gesture recognizer for swipe or tap. I only needed tap so I put a clear button inside A and B, and in its button event I called the above code.
I would put a UISwipeGestureRecognizer on your cell and then when swiped use a UIView transition animation. (See UIView Documentation). Should do what you want.
I need to modify a view's modal presentation with this parameters:
1 - Modal view only fills the ipad's right half of the screen.
2 - The animation runs from the left half of the screen.
I have search in iosframeworks.com, cocoacontrols.com, the books from big nerd rach, ios recipes, ios pushing the limits, stackoverflow and google. Is some posibility to do that?
Thanks for your assistance
For testing, after two days of searching answers, I create the following code, I'm executing the following code since the root view controller CMMainView, the viewcontroller CMVistaModal is empty, its doesn't have any overrided method nor xib nor another variable, the device family is iPad
-(IBAction)accion:(id)sender
{
CMVistaModal *modal = [[CMVistaModal alloc] init];
[modal setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:modal animated:NO completion:nil];
[modal.view.superview setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[modal.view.superview setFrame:CGRectMake(800, 120, 200, 500)];
[UIView animateWithDuration:1 animations:^{
modal.view.superview.transform = CGAffineTransformMakeTranslation(-200, 0);
}];
}
how can i perform the same operation but overriding the methods from CMVistaModal?
Absolutely. Just make a new view and add it to your existing view and animate it into position. You can have another view appear behind it blocking any touches to other views.
Anything is possible. It just depends on how much work you wish to put in.
So a standard UIModalPresentationFormSheet or UIModalPresentationPageSheet comes for free. But what you want isn't standard so you have to bake your own.
What I would do here is create a "fake" modal.
With
XYViewController -> Container View
Container View -> Semi Opaque blocker
-> Half Screen Content
The blocker covers the entire screen and goes in immediately and prevents interaction with the rest of the UI
Then animate the "Half Screen Content" in from the left with a standard frame animate. How you choose to dismiss this fake modal is up to you but if it comes in from left perhaps it should depart to the left.
In my app I have been using page and form modal view controllers like the following:
quickTemplateViewer.modalPresentationStyle = UIModalPresentationPageSheet;
quickTemplateViewer.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[parent presentModalViewController:myView animated:YES];
I have an offset close button that hangs over the view on the top left (the view is slightly smaller than the designated modal view size), and it has been working well as the background of hte modal view is partially transparent.
I upgraded to 4.2.1 and suddenly instead of a semi-transparent black background with a drop shadow I have a white background with rounded corners. Is there a new setting to turn it back to transparent?
Thanks
I spent all day searching for a solution on this, and eventually gave up and made my own solution.
Basically what I did was instead of loading my 'modal' with presentModalViewController, I just added a full size view with a black backgroundColor that had 80% opacity so that it shows the view underneath a little dimmed.
Inside of this view, I added the view that I usually loaded with presentModalViewController with the appropiate X & Y coordinates. this way, you mimic the behavior of the UIModalPresentationPageSheet: you get a dimmed background, and the user can't use any UIControl that's underneath.
it's probably not the best implementation, but it's the best I could come up with. Hope something similar works for you guys.
-- UPDATE
Mike asked how did I implement the animations that usually come with the modal. Basically, what I used was a UIView animationTransition:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromLeft forView:anotherView cache:YES];
[mainContainer addSubview:modal.view];
[UIView commitAnimations];