我想创建一个类似于在 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图片(左)和动画过渡(右)
关于iphone - 类似于ios7打开应用的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19486506/