I wanted to change the animation that occurs on a navigationControllers toolbar when the method setToolbarHidden is called. By default, when you set Hidden to YES and animation to YES, the toolbar simply drops off the screen. I'd like it to slide off the screen from left to right (much like when you hit the back button on a navbar and the previous view controller reasserts itself on the screen). Is this possible?
This isn't going to be perfect but it might be possible with something like this:
self.navigationController.toolbarHidden = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationFinished:finished:context:)];
CGRect frame = self.navigationController.toolbar.frame;
frame.origin.x = -1*frame.size.width;
self.navigationController.toolbar.frame = frame;
[UIView commitAnimations];
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context {
self.navigationController.toolbarHidden = YES;
}
I filed a bug report and it appears, unfortunately, there isn't a way to do this until Apple adds the feature themselves.
Related
I have used this code:
[[self.view viewWithTag:100] setTransform:CGAffineTransformMakeScale(0.009, 0.009)];
UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:0];
[[self.view viewWithTag:100] setTransform:CGAffineTransformMakeScale(1, 1)];
[UIView commitAnimations];
in viewWillAppear of my popup view.
The code works fine on simulator and produces nice effect in which my view appears to grow from center, however on device the animation effect is absent its more like sleep of 0.5 and then all off a sudden view appears.
Since this view is used liberally i don't want to increase duration any help?
Actually the code sample works for me in viewDidLoad and viewWillAppear.Increased the time and animation works fine here.
Why use this method?Apple provides a new and better technique with blocks to do the view animations.
Try this
[[self.view viewWithTag:100] setTransform:CGAffineTransformMakeScale(0.009, 0.009)];
[UIView animateWithDuration:10.5 animations:^{
[[self.view viewWithTag:100] setTransform:CGAffineTransformMakeScale(1, 1)];
}];
I have a very peculiar problem. In an iOS app I've developed, after running the animations below I find that various other elements of the UI now animate whenever they appear.
For instance, once these animations below are run, every time I navigate to a new tab in my app, all the UI elements animate from the top left corner of the iphone to their proper positions. I have specified no animations for these UI elements in the other tabs and in fact even elements that I have no access to, like the activity indicator in the iPhone status bar, begin to animate all on their own.
What is going on? Why does this occur only after the animation below is executed? Before running this animation (with a button press) all other UI elements in other app tabs do not animate at all when they appear, which is the expected behaviour.
- (IBAction) btnChosenPostcodeClicked:(id)sender {
//prep animations
startView.alpha = 1.0;
postcodeView.alpha = 0.0;
[self.view addSubview:postcodeView];
[UIView beginAnimations:#"ChosenPostcodeAnimation01" context:nil];
[UIView setAnimationDuration:animationSpeed];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(chosenPostCodeFadeoutAnimationDone:finished:context:)];
startView.alpha = 0.0;
[UIView commitAnimations];
}
- (void)chosenPostCodeFadeoutAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
//prep animations
postcodeView.alpha = 0.0;
[UIView beginAnimations:#"ChosenPostcodeAnimation02" context:nil];
[UIView setAnimationDuration:animationSpeed];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
CGRect newRect = CGRectMake(42, 157, 239, 180);
imvBubble.frame = newRect;
postcodeView.alpha = 1.0;
}
You're missing a
[UIView commitAnimations];
in chosenPostCodeFadeoutAnimationDone so absolutely everything you do is becoming part of the animation!
I need to show fade-in kind of transition effects while the view changes its orientation from one mode to other. Can anyone suggest me how to get that?
I would use an animation block inside of this method like so:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[UIView beginAnimations:#"InterfaceFade" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:duration];
// Change properties to animate here (Ex: view.alpha = 0.0)
[UIView commitAnimations];
}
I have a have a strip of UIViews that slides horizontally behind a UIView "window". Only the UIViews within the bounds of the "window" are seen. As a view becomes hidden I would like to be notified so that I can perform some task with the just hidden view. What is the best way to do this?
In your UIScrollViewDelegate:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// left and right bounds of the subview in relation to the scrollview
CGFloat left = mySubview.frame.origin.x - myScrollView.contentOffset.x;
CGFloat right = left+mySubview.frame.size.width - myScrollView.contentOffset.x;
if(right<=0 || left>=myScrollView.frame.size.width){
// The view is not visible
}
}
this checks if either the left or right side of the subview is visible.
Add a callback selector to your animation:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:theView cache:NO];
[UIView setAnimationDidStopSelector:#selector(animationDone)];
theView.frame = newFrame;
[UIView commitAnimations];
I have a refresh button on my iphone screen that refreshes a table in the current view.
The screen refresh beautifully, but is there a way I can make the screen dim and then lighten again after the table has refreshed?
You could place a non-opaque view with a black background over the view you wish to dim. This would have an alpha value of 0 by default and thus be transparent. You could then use a UIView animation to set the black views alpha from 0 to 0.5 (say) and then back.
Note: The code below has not been tested but I have used similar to achieve the same effect.
...
dimView.alpha = 0.0f;
[UIView beginAnimations#"fade" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView setAnimationRepeatAutoreverses:YES];
dimView.alpha = 0.5f;
[UIView commitAnimations];
...
}
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
dimView.alpha = 0.0f;
}
Could you load a black, 50% alpha view over the top, possibly fade in?