类似于在ios7中打开应用程序的动画 [英] animation similar to opening app in ios7

查看:76
本文介绍了类似于在ios7中打开应用程序的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个类似于iOS7中的iPhone打开的动画。在这个动画中,它只显示应用程序正在从哪个点开始并在同一点关闭。

I want to create an animation similar to app opens in iPhone in iOS7. In this animation it just shows that app is opening from which point and closing at same point.

任何人都可以帮助我吗?

Can anyone please help me?

推荐答案

@property (weak, nonatomic) IBOutlet UIImageView *bg;
@property (weak, nonatomic) IBOutlet UIImageView *cal;
…

bool nowZoomed = NO;
CGRect iconPosition = {16,113,60,60}; // customize icon position

- (CGRect)zoomedRect // just a helper function, to get the new background screen size
{
    float screenWidth = UIScreen.mainScreen.bounds.size.width;
    float screenHeight = UIScreen.mainScreen.bounds.size.height;

    float size = screenWidth / iconPosition.size.width;
    float x = screenWidth/2 - (CGRectGetMidX(iconPosition) * size);
    float y = screenHeight/2 - (CGRectGetMidY(iconPosition) * size);

    return CGRectMake(x, y, screenWidth * size, screenHeight * size);
}

- (IBAction)test
{
    float animationDuration = 0.3f; //default
    if (nowZoomed) // zoom OUT
    {
        [UIView animateWithDuration:animationDuration animations:^{ // animate to original frame
            _cal.frame = iconPosition;
            _bg.frame = UIScreen.mainScreen.bounds;
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:animationDuration/2.0f animations:^{ // then fade out
                _cal.alpha = 0.0f;
            } completion:^(BOOL finished) {
                _cal.hidden = YES;
            }];
        }];
    }
    else // zoom IN
    {
        _cal.alpha = 0.0f;
        _cal.hidden = NO;
        [UIView animateWithDuration:animationDuration/2.0f animations:^{ // fade in faster
            _cal.alpha = 1.0f;
        }];
        [UIView animateWithDuration:animationDuration animations:^{ // while expanding view
            _cal.frame = UIScreen.mainScreen.bounds;
            _bg.frame = [self zoomedRect];
        }];
    }
    nowZoomed = !nowZoomed;
}



您可以通过创建这样的示例项目来测试它:




  • 像我一样从模拟器制作两个屏幕截图(主屏幕和日历视图)或抓住这两个:主屏幕 / 日历

  • 在故事板中添加2个图像视图和1个按钮

  • 使背景图像视图与整个屏幕一样大

  • 以及具有此尺寸的其他图片视图: {16,113,60,60}

  • 创建 IBOutlet 两者(前两行代码)

  • 将按钮操作目标设置为 - (void)测试

  • you can test it, by creating a sample project like this:

    • make two screenshots from simulator like I did (homescreen and calendar view) or grab these two: homescreen / calendar
    • add 2 image views and 1 button into storyboard
    • make the background image view as big as the whole screen
    • and the other image view with this dimensions: {16,113,60,60}
    • create an IBOutlet for both (the very first two lines of code)
    • set the button action target to -(void)test

    • 故事板图片(左)和动画过渡(右)

      这篇关于类似于在ios7中打开应用程序的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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