I am developing iOS game and need custom animation so I am using this method
CGRect basketTopFrame = mainScreenView.frame;
basketTopFrame.origin.x = 320;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
mainScreenView.frame = basketTopFrame;
[UIView commitAnimations];
in the .h file I have declared mainScreen like this
IBOutlet UIView *mainScreenView;
So in the IB I have put UIView in the view in the interface and hooked it up with mainScreenView
So in the mainViewScreen the view sometimes shows up sometimes doesn't (works on the 2nd try) however when I remove the animation code it works perfectly fine..I don't know what is happening any help would be appreciated thanks
edit
this is how I added the view
MainScreen *mainScreen = [[MainScreen alloc]initWithNibName:#"MainScreen" bundle:nil];
[mainScreenView addSubview:mainScreen.view];
I tried it in a sandbox project, and this worked for me:
- (IBAction)buttonTouched:(id)sender {
myView.transform = CGAffineTransformMakeTranslation(-320, 0);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
myView.transform = CGAffineTransformMakeTranslation(0,0);
[UIView commitAnimations];
}
Looks like you are trying to move something off screen. An easier way is to do this
[UIView beginAnimations:#"UIBase Hide" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
mainScreenView.transform = CGAffineTransformMakeTranslation(320,0); //slide view to the right.
[UIView commitAnimations];
note: using 320 on the Translation wont move the view to the 320th pixel of the screen rather it moves your view 320px to the right. So if your mainScreenView is at origin.x = 100. After this translation it is now at 420.
To move it back do
self.transform = CGAffineTransformIdentity;
Related
I have a method to animate and reset the view which is given below.
-(void)animateToFocus:(BOOL)animate index:(NSInteger)index {
if (animate) {
[UIView beginAnimations:#"Scroll" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationsEnabled:YES];
self.view.frame = CGRectMake(0, -50*index, self.view.bounds.size.width, self.view.bounds.size.height);
[UIView commitAnimations];
} else {
[UIView beginAnimations:#"Scroll" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationsEnabled:YES];
self.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
[UIView commitAnimations];
}
}
When I pass YES and a tag in this method, it will animate to top and when I pass NO it will reset the view.
It works perfectly in IOS6.When i update to IOS 7, resetting done as:
It will not animate completeley and a black space appear in the bottom. Can u please help me to solve this?
I'm guessing that's a UITableView inside?
If so, you shouldn't be animating it's frame you should use:
– scrollToRowAtIndexPath:atScrollPosition:animated:
or:
– scrollToNearestSelectedRowAtScrollPosition:animated:
I am trying to do an animation where a UIView should come from top to bottom(or till mid of screen) when we toch on top of the screen and drag down.
Set your view frame, and then add these code in your button action or else.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:1.0];
[yourView setFrame:CGRectMake(0, 250, 320, 100)];
[UIView commitAnimations];
set positions according to ur need
[UIView beginAnimations:#"DragView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.5f];
self.dragView.frame = CGRectMake(newXPose, newYPose,width, height);
[UIView commitAnimations];
I have customized the UIViews by adding images to make it look like radio button or check boxes, but for my spec I want to make the UIAlertView look like this...
Can anyone suggest how to do this?
Thanks!
You can design custom view and can give animation to it as alert view using this code
-(void)initialDelayEnded
{
alert_upload.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
alert_upload.alpha = 1.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1/1.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(bounce1AnimationStopped)];
alert_upload.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
[UIView commitAnimations];
}
- (void)bounce1AnimationStopped {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5/2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(bounce2AnimationStopped)];
alert_upload.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
[UIView commitAnimations];
}
- (void)bounce2AnimationStopped {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5/2];
alert_upload.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}
alert_upload is UIView.
There’s many previous questions about this topic, one of them links this component that lets you create custom alerts and action sheets. Might be a good way to start.
You can create your own customized alert views, Apple wont reject it until unless user interaction.
[UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelay:0.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:viewHelp cache:YES];
[self.view addSubview:viewHelp];
[UIView commitAnimations];
Where am I doing wrong? I am able to switch the view but I am not able to animate it.
[self.view addSubview:viewHelp]; the animation is just literally adding the subview, you need to work out what animation you want, and then apply it by changing values in the views frame property.?
follow this thread : click me
I would like to have a category for UIViewController containing few simple methods to move the view controller's view around, fading it etc...
For example the method below fades in/out a the VC's view.
I'm not using instance variables and the onTransitionIn: method is called, the problem is the view doesn't fade in/out.
Can someone tell me what I'm doing wrong?
Thank you!
EXAMPLE:
#implementation UIViewController (UIViewControllerAdditions)
- (void)onTransitionIn:(BOOL)isIn {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:ANIM_DUR];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
int newAlpha = 1;
if (!isIn) {
newAlpha = 0;
[UIView setAnimationDidStopSelector:#selector(hideAnimationDidStop)];
}
// set the new alpha
self.view.alpha = newAlpha;
[UIView commitAnimations];
}
Try adding this:
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView: self.view cache:YES];
after the line:
[UIView setAnimationDelegate:self];
Also take a look at these:
iPhone UIView Animation Best Practice
How to animate View swap on simple View iPhone App?