类似于在ios7中打开应用程序的动画

Alf*_*lfa 10 iphone ipad ios ios7

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

谁能帮帮我吗?

小智 18

@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;
}
Run Code Online (Sandbox Code Playgroud)

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

  • 像我一样从模拟器制作两个截图(主屏幕和日历视图)或抓住这两个:主屏幕/日历
  • 在故事板中添加2个图像视图和1个按钮
  • 使背景图像视图与整个屏幕一样大
  • 以及具有此尺寸的其他图像视图: {16,113,60,60}
  • IBOutlet为两者创建一个(前两行代码)
  • 将按钮操作目标设置为 -(void)test

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