UIView动画

发布于 2024-10-02 02:30:53 字数 105 浏览 0 评论 0原文

我正在尝试在这里为 UIView 制作动画。它看起来像一个矩形,我只想将其转换为我的坐标。

那么,我怎样才能让它动起来呢?我试图找到一些教程,但没有成功。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

红衣飘飘貌似仙 2024-10-09 02:30:53

在iOS 4中,UIView块动画方法是最简单的:

[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:动画:

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:

梦忆晨望 2024-10-09 02:30:53

下面是一个将视图动画移出屏幕的示例。您应该能够根据您的需要稍微调整它:


[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];

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];
一场春暖 2024-10-09 02:30:53
//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];
}
//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];
}
木格 2024-10-09 02:30:53

使用“QuartzCore.framework”
有了这些动画。

-(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];
}

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];
}
温柔少女心 2024-10-09 02:30:53
[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];

绝对工作得很好。

[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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文