UIView翻转动画 [英] UIView flip animation

查看:109
本文介绍了UIView翻转动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的游戏中,我的主要UIView上有一个较小的UIViews网格。随机地,框将变为不同的颜色,此时用户可以触摸它们以获得一个点。当他们触摸盒子时我想要显示某种动画,理想情况下类似于XCode本身提供的模态水平翻转segue。如何在不实际转换到另一个UIView的情况下进行此动画?

In my game I have a grid of smaller UIViews hosted on my main UIView. Randomly the boxes will turn a different colour, at this point a user can touch them to score a point. When they touch the box I want to show some kind of animation, ideally something similar to the modal horizontal flip segue that XCode offers natively. How can I do this animation without actually transitioning into another UIView?

推荐答案

您可以像这样尝试动画视图转换(对于垂直翻转):

You could simply try and animate the view transform like this (for a vertical flip):

[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                 animations:^(void) {
                     view.transform = CGAffineTransformMakeScale(1, -1);
                 }
                 completion:nil];

或者为了更好的控制,您可以查看 iOS-Flip-Transform

or for better control you could have a look into iOS-Flip-Transform.

编辑:

对于影子来说,试试这个:

for the shadow thing, try this:

    view.layer.shadowColor = [UIColor blackColor].CGColor;
    view.layer.shadowOpacity = 0.75;
    view.layer.shadowRadius = 15.0;
    view.layer.shadowOffset = (CGSize){0.0,20.0};

[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                 animations:^(void) {
                     view.transform = CGAffineTransformMakeScale(1, -1);
                 }
                 completion:^(BOOL b) {
    view.layer.shadowColor = [UIColor clearColor].CGColor;
    view.layer.shadowOpacity = 0.0;
    view.layer.shadowRadius = 0.0;
    view.layer.shadowOffset = (CGSize){0.0, 0.0};
                 }];

我希望这对你有用。您可以根据需要更改阴影设置。不要忘记导入QuartzCore / QuartzCore.h。

I hope this works fine for you. You can change the shadow settings as you like. Don't forget to import QuartzCore/QuartzCore.h.

这篇关于UIView翻转动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆