UIView animation

2019-02-05 09:51发布

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.

5条回答
叛逆
2楼-- · 2019-02-05 10:32

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楼-- · 2019-02-05 10:37

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];
查看更多
倾城 Initia
4楼-- · 2019-02-05 10:40
//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];
}
查看更多
一纸荒年 Trace。
5楼-- · 2019-02-05 10:45
[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.

查看更多
家丑人穷心不美
6楼-- · 2019-02-05 10:53

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];
}
查看更多
登录 后发表回答