UIView animation

2019-02-05 10:21发布

问题:

I am trying to animate a UIView here. It looks like a rectangle, and I just want to translate it to my coordinations.

So, how can I animate it? I tried to find some tutorials, but without success.

回答1:

Here is an example of animating a view to move off screen. You should be able to slightly adjust it for your needs:


[UIView beginAnimations:@"bucketsOff" context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDelegate:self];
//position off screen
[bucketView setCenter:CGPointMake(-160, 377)];
[UIView setAnimationDidStopSelector:@selector(finishAnimation:finished:context:)];
//animate off screen
[UIView commitAnimations];


回答2:

In iOS 4, the UIView block animation method is easiest:

[UIView animateWithDuration:1.0 animations:^{
    myView.frame = myNewFrameRect;
}];

http://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/clm/UIView/animateWithDuration:animations:



回答3:

//try this AnimationTransitionCurlDown \UP

-(void)pageDown
{
 [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self cache:YES];

        [UIView commitAnimations];
}

-(void)pageUP
{
[UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self cache:YES];

        [UIView commitAnimations];
}

//flip uiviews  using animation



-(void)FlipFromLeft
{
[UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self cache:YES];

        [UIView commitAnimations];
}

-(void)FlipFromRight
{
[UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self cache:YES];

        [UIView commitAnimations];
}


回答4:

Use "QuartzCore.framework" With these animations.

-(void)viewSlideInFromRightToLeft:(UIView *)views
{
    CATransition *transition = nil;
    transition = [CATransition animation];
    transition.duration = 0.5;//kAnimationDuration
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype =kCATransitionFromRight;
    transition.delegate = self;
    [views.layer addAnimation:transition forKey:nil];
}

-(void)viewSlideInFromLeftToRight:(UIView *)views
{
    CATransition *transition = nil;
    transition = [CATransition animation];
    transition.duration = 0.5;//kAnimationDuration
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype =kCATransitionFromLeft;
    transition.delegate = self;
    [views.layer addAnimation:transition forKey:nil];
}

-(void)viewSlideInFromTopToBottom:(UIView *)views
{
    CATransition *transition = nil;
    transition = [CATransition animation];
    transition.duration = 0.5;//kAnimationDuration
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype =kCATransitionFromBottom ;
    transition.delegate = self;
    [views.layer addAnimation:transition forKey:nil];
}

-(void)viewSlideInFromBottomToTop:(UIView *)views
{
    CATransition *transition = nil;
    transition = [CATransition animation];
    transition.duration = 0.5;//kAnimationDuration
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype =kCATransitionFromTop ;
    transition.delegate = self;
    [views.layer addAnimation:transition forKey:nil];
}


回答5:

[UIView beginAnimations:@"your text" context:nil];
[UIView setAnimationDuration:0.4]; //Your animation duration
[UIView setAnimationDelegate:self];
//
write your code here , what you want to animate
//
[UIView commitAnimations];

Working Fine definitely.