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?
Related
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.
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 want to create an animation that moves and rotates a UIView at the same time. I tried the following code:
[UIView beginAnimations:#"MoveAndRotateAnimation" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:kAnimationDuration];
myView.frame = newFrame;
myView.transform = CGAffineTransformMakeRotation(0.4);
[UIView commitAnimations];
The result is, that after the animation has finished the view is drawn incorrectly (some parts are not visible anymore). If I only change the frame OR the transformation for the animation, the view draws correctly. The problem only occurs if I set both the frame and transformation.
What would be the correct way to animate moving and rotating of a view at the same time?
You can't use frame, bounds, or center if you are also animating things like rotation. You need to use CGAffineTransforms for everything and concatenate them together. Like so:
CGAffineTransform transform = CGAffineTransformMakeTranslation(100,100);
transform = CGAffineTransformRotate(transform, 0.4);
[UIView beginAnimations:#"MoveAndRotateAnimation" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:kAnimationDuration];
myView.transform = transform;
[UIView commitAnimations];
Try doing it this way: (Moving left and rotating, just for example)
[UIView beginAnimations:#"MoveAndRotateAnimation" context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:kAnimationDuration];
CGPoint center = CGPointMake(-200, self.view.center.y);
self.view.transform = CGAffineTransformMakeRotation(-0.5);
self.view.center = center;
[UIView commitAnimations];
The center point locations would be the point you wish to make the view move, of course.
The problem is probably with your new frame size as compared to original frame size. View frame is a bit tricky when you rotate a frame:
Frame is in superviews coordinate system. So, when you rotate a rectangle, the new frame will be the smallest rectangle in superview's coordinate system which contains the view.
e.g. if you have a square view with frame size of (100*100) and rotate it by 45 degrees your new frame would have a size of (141*141) and if you set the frame to have a size of (100*100) you'll cut part of your view.
Look at here for better understanding of how view frame works.
You need to do this:
#pragma mark (Woblling animation)
CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-10.0));
CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(10.0));
self.view .transform = leftWobble; // starting point
[UIView beginAnimations:#"wobble" context:self.view ];
[UIView setAnimationRepeatAutoreverses:YES]; // important
[UIView setAnimationRepeatCount:11];
[UIView setAnimationDuration:1.00];
//[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(wobbleEnded:finished:context:)];//should be same as written
self.view .transform = rightWobble; // end here & auto-reverse
[UIView commitAnimations];
and then implement these methods. They are necessary to keep your view in the same position after rotation.
- (void) wobbleEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
if ([finished boolValue]) {
UIView* item = (UIView *)context;
item.transform = CGAffineTransformIdentity;
}
}
Use this method if you are using navigation and when you navigate from one view to another, then your view would be at the same place.else leave this method:
- (void)viewWillAppear:(BOOL)animated
{
UIView* item = self.view;
item.transform = CGAffineTransformIdentity;
}
I had the same problem but did some experiments and came up with this solution.
I am working on apllication for iphone in xcode 3.1.
I want similar two images to disappear when touched one after other.
I have succeed in displaying two images on iphone simulator on touching
'PlAY' button.
Now i want that when two same images are 'touched' one after another,they should disappear.
Expect code in Objective C.
You can do this, by using simple animations the view should disappear, later you can cast the context inside the UIView animations delegate and start a second animation.
aView.alpha = 1.0;
[UIView beginAnimations:nil context:#"Context1"];
[UIView setAnimationDuration: 1.0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
[UIView setAnimationBeginsFromCurrentState:YES];
aView.alpha = 0.0;
[UIView commitAnimations];
This id the delegate method you should implement:
-animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
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];
}