iOS - Updating label during animation transition? - iphone

I have a UIView on the screen that contains a few labels. I am trying to have a transition where flips the view, and as soon as I am half way through the nimation I want to be able to update the labels. How Can I achieve this?
[UIView transitionWithView:self.myView
duration:.7
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
// It doesn't update the labels here, until I scoll the tableview (containing the view)
//[self.myView update];
}
completion:^(BOOL finished){
// It doesn't look nice here because it doesn't look smooth, the label flashes and changes after the animation is complete
//[self.myView update];
}];

The problem was that I had shouldRasterize enabled which was not allowing the content to be updated during an animaton. Solution was to turn off rasterization before the animation and turn it back on after animation completion.
The reason why I didn't get rid of rasterization is that the view is inside a tableView, and rasterization still helps while scrolling through the tableView.
self.layer.shouldRasterize = NO;
[UIView transitionWithView:self
duration:animationDuration
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{/*update the content here, I did it outside of the transition method though*/}
completion:^(BOOL finished){
if (finished)
{
self.layer.shouldRasterize = YES;
}
}];

Related

UINavigationController undoes changes to previous UIView

I have a navigation controller with a couple of view controllers in it. In the first view controller (the app's initial one) I perform an animation, which moves two UIImageViews around, and fades in some additional ui elements. Now, when I push the next view controller and then go back to the initial one, the transformations are gone and the image views are exactly where they were when loaded from the storyboard. The additional ui elements, however, are still visible and so is the text I've entered in some UITextFields. So the view controller is not entirely reset to its initial state but somehow the performed animations are undone. Can anybody tell me whether this is regular behavior and - if so - how I can preserve the transformations?
A little more disclosure: I'm simply setting off a regular animation upon hitting a button...
[UIView animateWithDuration:0.4
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.firstView.center = firstCenter;
self.secondView.center = secondCenter;
}
completion:^(BOOL finished) {
// Upon complection fade in additional ui elements
[UIView animateWithDuration:0.4
animations:^{
self.firstElement.alpha = 1.0;
self.secondElement.alpha = 1.0;
self.thirdElement.alpha = 1.0;
}
completion:^(BOOL finished) {
[self.activityIndicator stopAnimating];
}];
}];
... and then pushing the next view controller after hitting another button.
[self.navigationController pushViewController:_nextViewController animated:YES];
As far as I can see I'm not doing anything funky here, so any help is appreciated.

How to impelment Phone call animation like iPhone's default Phone application does?

My application has VOIP calling. In that I want to implement animation like iPhone's default Phone application does when User Clicks on Call button on dial Pad and animation that is done on End call button.
I have researched alot about this but haven't find anything yet. Any help will be appreciated on this topic.
Right now I have implemented scaling animation like below:
- (void)animateFadingOut{
self.view.transform = CGAffineTransformMakeScale(1.00, 1.00);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[self performSelector:#selector(push) withObject:nil afterDelay:0.35];
self.view.transform = CGAffineTransformMakeScale(0.00, 0.00);
//set transformation
[UIView commitAnimations];
}
- (void)push
{
self.view.transform = CGAffineTransformMakeScale(1.00, 1.00);
// push navigation controloller
CallViewController *objCallViewController = [[CallViewController alloc] initWithNibName:#"CallViewController_iPhone" bundle:nil];
[self setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:objCallViewController animated:NO];
[objCallViewController release];
[self setHidesBottomBarWhenPushed:NO];
[[AppDelegate shared] setTabHidden:TRUE];
}
But It is not giving me exact animation that default Phone application has
Here is what I might try if I was trying to create animations.
CGRect movementFrame = self.view.frame;
//Make position and size changes as needed to frame
movementFrame.origin.x = 0;
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
/*
Animation you want to commit go here
Apply movementFrame info to the frame
of the item we want to animate
*/
//If you wanted a fade
self.view.alpha = !self.view.alpha //Simply says I want the reverse.
self.view.frame = movementFrame;
//Example of what you could do.
self.view.transform =CGAffineTransformMakeScale(1.00, 1.00);
} completion:^(BOOL finished) {
//Things that could happen once the animation is finished
[self push];
}];
This has not been tested for your case. Therefore I am also not sure if it will help you, but hopefully it will. Good luck to you.
*Edit*
So I reviewed the animation on an iPhone and it appears to me to be a series of animations happening at once.
You have what I presume to be the UIActionSheet animating down.
The top section overlay sliding up its y-axis.
Then you have, which I haven't mastered yet, a split in the back view that animates its x-axis in opposite directions which cause the split.
Finally you have the new view scale up to take frame for the effect.
I can't say 100% this how they have done it, however if I was going to attempt to recreate this, I would likely start here.
Hello there so after just quickly coming up with an animation I got pretty close it could use some tweaks.
It took me three views to do a
topView, bottomView, and backView.
Also took into account the view that you would be loading in. viewToLoadIn
`-(void)animation{
CGRect topMovementFrame = self.topView.frame; //Set dummy frame to modify
CGRect bottomViewFrame = self.bottomview.frame;
topMovementFrame.origin.y = 0 - self.topView.frame.size.height; //modify frame's yAxis so that the frame sits above the screen.
bottomViewFrame.origin.y = self.view.frame.size.height; //modify frame's yAxis to the it will sit at the bottom of the screen.
[self.viewToLoadIn setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
//Animation
self.topView.frame = topMovementFrame; //Commit animations
self.bottomview.frame = bottomViewFrame;
self.backView.alpha = !self.backView.alpha;
self.backView.transform = CGAffineTransformMakeScale(100, 100);
self.viewToLoadIn.transform = CGAffineTransformMakeScale(2.0, 3.0);
*MAGIC*
} completion:^(BOOL finished) {
//Completion
//Clean up your views that you are done with here.
}];
}`
So then When they pressed the button I had setup this animation would happen.
Also at first I thought that the setup might contain a UIActionStyleSheet. which it still might but this is a pretty handy built in functionality. But the fact that you can interact with the screen lead me to think a custom view. It would be easier in my opinion.
I hope this helps you even if it just a little bit.
Take care ^^

animateWithDuration: corrupts smooth progressbar increment

In one of my views i need to animate frame property of a UIImageView and while doing it i want to show a progress bar(UIProgressView) in the title view of the navigation bar.The problem is the if i comment out the following animation blocks the progress bar is updated as expected smoothly.On the other hand due to the following animation the progress bar stops in severals places and carries incrementing again.
//add message bubble
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^
{
animationBubbleImageView.alpha = 1;
}
completion:^(BOOL finished)
{
[self removeAutoCorrectionAndHighlight];
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^
{
CGRect bubbleFrame = CGRectMake(animationBubbleImageView.frame.origin.x,
animationBubbleImageView.frame.origin.y,
bubbleSize.width,
bubbleSize.height);
[animationBubbleImageView setFrame:bubbleFrame];
messageLabel.alpha = 1;
}
completion:^(BOOL finished)
{
[self sendSubviewToBack:textView];
[self.delegate moveBubbleToTableCell];
}];
}];
animation blocks do not block the main thread but what coudl be the reason of unsmooth beahviout of th progress view ?
UPDATE: What i want to achive is the MessagesApp bubble animation in IOS.While the typed message becomes a bubble and flies to its place the progress bar should increment slowly.
If i try the same thing withou animation progressbar increments normal.
Try putting the progress bar animation in the same animation as the bubble animation. Or put them all into an animation group.
Have you tried Instruments to see what's happening?
Wild guess: you can also check whether the two views inadvertently overlap.
If feasible you can also try to group together the animations, as suggested by "Dad".
Best, Akos

UIView TransitionFromView disables scrolling

Hey there StackOverflow! I've finished programming my app, and everything is working fine- so I've decided that since the function part is done, I want to start working on form. However, I have a bit of code that's giving me trouble, and I'm not sure why. My app has two views that I switch between. In viewDidLoad, I have these two lines of code:
[PlannerView setScrollEnabled:YES];
[PlannerView setContentSize:CGSizeMake(320, 735)];
and then later, I switch between the main view and planner view when a button is pressed, like this:
if (isPlannerView) {
// [self setView:MainView];
[UIView transitionFromView:PlannerView
toView:MainView
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished){
[self setView:TimerView];
}];
isPlannerView = NO;
} else {
[UIView transitionFromView:MainView
toView:PlannerView
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished){
}];
// [self setView:PlannerView];
isPlannerView = YES;
}
Now, when I use hte commented line of code (self setview), it will scroll with no problems. However, when I use UIView transitionFromView, it no longer scrolls. Any idea what is going wrong here?
The documentation for transitionFromView:toView:duration:options:completion: says:
This method modifies the views in their view hierarchy only. It does
not modify your application’s view controllers in any way. For
example, if you use this method to change the root view displayed by a
view controller, it is your responsibility to update the view
controller appropriately to handle the change.
So make sure that viewDidLoad: is actually being called. It also states:
During an animation, user interactions are temporarily disabled for
the views being animated. (Prior to iOS 5, user interactions are
disabled for the entire application.) If you want users to be able to
interact with the views, include the
UIViewAnimationOptionAllowUserInteraction constant in the options
parameter.
So make sure that user-interaction is enabled on the view after the animation is finished.
completion:^(BOOL finished){
[PlannerView setUserInteractionEnabled:YES];
}];
Source: UIView Class Reference

our fade animation freezes button & slider controls

I have a simple photo transition on an iPad program that precludes operator interaction during the transition. The 2 photos are approx 200kb each and the fade is by changing their alphas with the following code;
-(void)photoLoopAnimation
{
// FADE block animation method - THIS contains the basic animation features
[UIView animateWithDuration:5.2 delay:delaySeconds
options:UIViewAnimationOptionTransitionNone
animations:^{
viewTop.alpha = 0.0;
viewBottom.alpha = 1.0;
}
completion:^(BOOL finished) { // remove both views & loop
[viewTop removeFromSuperview];
[viewBottom removeFromSuperview];
[viewTop release];
[viewBottom release];
[self photoLoop];
//[self performSelectorInBackground:(#selector(photoLoop)) withObject:nil];
}];
}
My understanding is that the animation block works as a background thread (task?), & shouldn't lock control of the app while it is executing. Can anyone offer any incite? (insight)
Thanks,
CPL
Try adding the UIViewAnimationOptionAllowUserInteraction option if your controls are being animated.