When I start a movie in a MPMoviePlayerController, controls stay at the top for few seconds. After that, they fade out.
I want simulate this effect when I use MPMovieControlStyleNone in controlStyle property, but controls disappear abruptly. I tried to use animations without success with the following code:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.50f];
self.myMoviePlayer.controlStyle = MPMovieControlStyleNone;
[UIView commitAnimations];
Someone have any idea how I can make that?
Any help will be appreciated.
Thanks.
If I understand you correctly, you are planning to hide custom controls in a similar fashion to the original controls.
You will need hide your custom controls using something like
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.50];
self.customControlsView.alpha = 0.0f;
[UIView commitAnimations];
to achieve that effect. controlStyle is not an animatable property.
On tops, you will need to stick to controlStyle = MPMovieControlStyleNone anyways throughout the lifetime of your MPMoviePlayerController as that is the only way to prevent the original controls from appearing.
Related
I have several UI elements in a nib that are positioned using autolayout and constraints. When the view loads i move the elements off screen using
[self.button setTransform:CGAffineTransformMakeTranslation(-self.button.frame.origin.x * 2 + self.button.frame.size.width, 0)];
then when the view appears i use the following to ease the button into the correct position on the page. However it seems to move too far across.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2];
[self.button setTransform:CGAffineTransformIdentity];
[UIView commitAnimations];
Am i doing something wrong? Is there a better way to move the button off the screen with CGAffineTransform?
Any help would be great
The issue was caused by autolayout and the best way to animate UI elements when using autolayout is to change the constraints
I am trying to make UIView glow back and forth twice. My animation below works but just after it has finished it goes to the state that I animated it to, and not the original. I set autoreverses to YES so why is it not going back to original state ?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationRepeatCount:2];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
textDetailView.layer.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.3].CGColor;
[UIView commitAnimations];
The animation reverses but the value doesn't. After the animation completes it removes itself from the view (actually from the views layer) and the view appears to have the properties that have been set on it.
You could set the value back in a completion block or in the selector for the older UIView animation that you are using.
Alternatively, for animations where the value doesn't change you could benefit from using Core Animation (which doesn't hangs the value (after the animation the view goes bak to its original state)).
You would need to import QuartzCore.framework and include QuartzCore/QuartzCore.h to get it to work.
The could would also need to be updated to something like this:
CABasicAnimation *myColorAnimation = [CABasicAnimation animationWithKeyPath:#"backgroundColor"];
[myColorAnimation setAutoreverses:YES];
[myColorAnimation setRepeatCount:2];
[myColorAnimation setDuration:0.3];
[myColorAnimation setToValue:(id)[myColor CGColor]];
// the default "from value" is the current value
[[textDetailView layer] addAnimation:myColorAnimation forKey:#"myColorKey"];
I have an uiview which i add a transition that removes it from an uiwindow using curlup animation. When the animation occurs the backside of the view is white...i would like to change the color of it or even put some of my own texture. Any help appreciated.
[UIView beginAnimations: #"Curl up" context:nil];
// wait for time before begin
[UIView setAnimationDelay:wait];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:viewToCurlUp cache:YES];
// druation of animation
[UIView setAnimationDuration:duration];
[UIView commitAnimations];
As far as I know, it is not possible to create a texture (ie: your own image) on a UIView. The color of 'back of the curl' should correspond to the background color you have set for your UIView. You can do this in the inspector in Interface Builder, or programmatically like so:
[view setBackgroundColor:[UIColor greenColor]];
where view is the UIView of interest. Use the appropriate color, of course.
Hope that helps.
Apple engineers responded that this is not possible in my case. I have asked them a few days ago.
I want to flip a view like the Mac OS X user switch,i have used this code
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myview cache:YES];
[myview removeFromSuperview];
[UIView commitAnimations];
But this flipping is different from mac os user switch, help me if you can..This code provides different flip.
There is no built-in "cube rotate" in iOS. You'd need to create it yourself. There are several ways to do this. One way to approach it is to put both views into a single superview, and apply a CATransform3D transform to the "target" view to create the box. Then animate a CATransform3D for the entire superview to rotate it. When you're done, remove the old "source" view.
See the Core Animation Programming Guide, particularly Transforming a Layer's Geometry, for more information.
I'm trying to transform a UISearchBar, like in Mobile Safari: touch in the search field and it grows while the location field shrinks.
My current animation to alter the width and position of the search field only animates the position: just before it slides to the right place, it simply snaps out to the right width. Here's my code:
[UIView beginAnimations:#"searchGrowUp" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
CGFloat findFieldWidth = findField.frame.size.width;
CGFloat urlFieldWidth = urlField.frame.size.width;
CGRect findFieldFrame = findField.frame;
CGRect urlFieldFrame = urlField.frame;
findFieldFrame.origin.x = findFieldFrame.origin.x - 150.0f;
findFieldFrame.size.width = findFieldWidth + 150.0f;
urlFieldFrame.size.width = urlFieldWidth - 150.0f;
urlField.frame = urlFieldFrame;
findField.frame = findFieldFrame;
[UIView commitAnimations];
I've modified this code slightly for the sake of presenting it here, but I hope this gives the gist.
Any guesses as to why this is happening would be appreciated!
Cheers,
Aaron.
I figured it out thanks to this post: Changing the size of the UISearchBar TextField?
Turns out the contents of a UISearchBar don't resize properly along with the outer layer. So you have to call -layoutSubviews: within the animation block after the frame is set on the searchbar. So the block ends like:
[findField setFrame:CGRectMake(findField.bounds.origin.y, findField.bounds.origin.y, findFieldWidth, findField.bounds.size.height)];
[findField layoutSubviews];
[UIView commitAnimations];
Props to Nick Farina!
I had the same problem when trying to animate the width of a UISearchBar.
On iOS 4 and later, I found that using UIViewAnimationOptionLayoutSubviews as an option for
+[UIView animateWithDuration:delay:options:animations:completion:]
fixed it.
The accepted answer works but according to Apple docs you "should not call this method". The clean solution is to use layoutIfNeeded method:
[UIView animateWithDuration:UINavigationControllerHideShowBarDuration
delay:0.f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[searchBar setFrame: ...
[searchBar layoutIfNeeded];
...
Enjoy!
Sorry this is a bit old, but I was running into a similar problem.
I didn't want to use layoutSubviews because the documentation says you shouldn't call that method directly.
What I did to solve my problem was call sizeToFit on the subview within the animation block.