Strange results using CGAffineTransformIdentity - objective-c

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

Related

Flipping a view that is contained on a view setup

I currently have a xib that is a standard view that has another view contained on top. I want the user to be able to click on this subview, and then have this subview flip over when pressed. I currently have code that flips the view around, but since I'm not explicitly assigning a new view, it just flips over and displays the same view. Here is my code when the button is pressed:
- (IBAction)flipCard:(id)sender
{
NSLog(#"Subview button was clicked!");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.frontOfView
cache:YES];
[UIView commitAnimations];
}
The biggest question is how to set this up. Do I need to create an entire view programmatically and then just call [[self view] addSubview: backOfView]*? Or is there a way to do this with interface builder?
*Note I haven't actually create a "backOfView" object, I'm not sure how I should create one at this point.
Try this one?
[UIView transitionFromView:self.frontOfView
toView:self.backOfView
duration:0.4f
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:nil];

Change backside color of uiview when using Curlup animation

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.

Fading out MPMoviePlayerController controls

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.

How to implement the effect of popping up tableview from bottom of screen?

I'm a newbie of Xcode and Objective-c. Recently I wanna do a task about popping up tableviews. When a button is pressed, the tableview should pop up from the bottom of the screen. The tableview will contain just a few items so I don't wanna it occupy full screen. I read the manual and found UIModalPresentationStyle, but it seems not fulfill my requirements. So what's the more accurate methods I can use?
While #Bharat J's answer is correct, those methods are deprecated in iOS 4.0.
The latest and greatest implementation is + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
Implemented as:
[UIView animateWithDuration:0.5 animations: ^{
tableView.frame = newFrame;
}
];
You can use below code to create an animation block . Set the frame for the table view as (0,480,320,0) When you hit a button change the frame of the table view in the animation block and make it to CGRectMake(0,200,320,280) or something .
[UIView beginAnimations:#"AnimateTableView" context:view];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
tableView.frame = CGRectMake(0, 200 , 320, 280);
[UIView commitAnimations];
The same animation block for hiding it again but with the frame again begin set to CGRectMake(0,480,320,0). This should work in your case .
Another option would be to use a UIActionSheet and add the uitableview as a subview.
Here is a very similar question about how to add a UIPickerview with similar effect.
Add UIPickerView & a Button in Action sheet - How?

Mac OS X quick user switch in iOS

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.