iphone - 类似于ios7打开应用的动画

标签 iphone ios ipad ios7

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

谁能帮帮我?

最佳答案

@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;
}

您可以通过创建一个示例项目来测试它:

  • 像我一样从模拟器中截取两个屏幕截图(主屏幕和日历 View )或抓取这两个:homescreen/calendar
  • 在 Storyboard中添加 2 个 ImageView 和 1 个按钮
  • 使背景 ImageView 与整个屏幕一样大
  • 以及具有此尺寸的其他 ImageView :{16,113,60,60}
  • 为两者创建一个IBOutlet(最开始的两行代码)
  • 将按钮 Action 目标设置为-(void)test

storyboard animation Storyboard图片(左)和动画过渡(右)

关于iphone - 类似于ios7打开应用的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19486506/

相关文章:

ios - Visual Studio 不会在 Debug模式下将配置文件应用于 MAUI iOS 应用程序

android - 移动项目的 SLA(服务水平协议(protocol))

ios - QuickBlox聊天Swift集成

iphone - 如何使用搜索栏实现基于单个字母的搜索?

javascript - 用 JavaScript 模仿 iPhone 主屏幕滑动

iphone - 如何在iOS模拟器中测试UI Interpolating Motion Effect?

ios - 使用 UIViewControllerInteractiveTransitioning 委托(delegate)协议(protocol)实现自定义 UIViewController 交互式过渡的正确方法

ios - iOS Cocoa-自定义uipickerview或类似版本

javascript - 如何使用 e.preventDefault(); 禁用、启用然后再次禁用 ipad/iphone 中的滚动?

objective-c - 我怎么知道什么时候播放视频?