类似于iOS中7打开应用Segue公司动画:的ViewController框架是不可调整大小 [英] Segue animation similar to opening an app in iOS 7: viewcontroller frame is not resizable
问题描述
我愿意创建一个类似于在开放的iOS 7的应用程序现在我认为这些措施将SEGUE动画:<一href=\"http://stackoverflow.com/questions/19486506/animation-similar-to-opening-app-in-ios7\">Non-segue实施,但遇到一个问题:如果自定义SEGUE正在实施中,code不能调整的ViewController的框架,这是动画的主体。正如我所看到的,它适用的ViewController的位置,但不能改变它的大小。我是正确,该属性viewcontroller.view.frame不能动画,并有保持不变,等于设备的屏幕尺寸?我已经实现了以 CGAffineTransformMakeScale
类似的东西,但它有点不可思议,所以,我在找更好的解决方案。下面我贴code我使用的SEGUE。
#进口ZoomSegue.h
#进口MiniMapViewController.h
#进口InteractiveMapViewController.h@implementation ZoomSegue - (无效){执行
InteractiveMapViewController * sourceViewController = self.sourceViewController;
MiniMapViewController * destinationViewController = self.destinationViewController; destinationViewController.view.alpha = 0.0;
destinationViewController.view.hidden = NO;
//只是为了检查,让使视图非常小。它定位到我们从SEGUE得到中心。
destinationViewController.view.frame = CGRectMake(_originatingPoint.x,_originatingPoint.y,60.0f,60.0f); [sourceViewController.view addSubview:destinationViewController.view];
浮animationDuration = 1.5F; [UIView的animateWithDuration:animationDuration / 2.0F动画:^ {
destinationViewController.view.alpha = 1.0F;
}]; [UIView的animateWithDuration:animationDuration动画:^ {
//只是为了检查,让使视图非常大。这是行不通的,虽然,该视图去左上角,因此位置工作,而不是大小
的CGRect X = CGRectMake(0.0,0.0,9590.0f,91366.0f); destinationViewController.view.frame = X;
}];
}
@结束
我不知道,如果你是正确的,但更好的方法来做到这一点无论如何是使用快照视图。这code把一个小快照在屏幕的中心,然后它扩展到全尺寸,
- (无效){执行
UIView的* sourceView =((*的UIViewController)self.sourceViewController)。查看;
UIView的* destinationView = [((*的UIViewController)self.destinationViewController)。查看snapshotViewAfterScreenUpdates:YES];
destinationView.frame = CGRectMake(0,0,5,5);
destinationView.center = CGPointMake(sourceView.center.x,sourceView.center.y);
[sourceView addSubview:destinationView]; [UIView的animateWithDuration:1
动画:^ {
destinationView.frame = sourceView.frame;
}
完成:^(BOOL完){
[自sourceViewController] presentViewController:动画[个体经营destinationViewController]:NO完成:无];
}];}
修改后:
下面是您所提供的该动画转换成赛格瑞的链接,code的翻译,
- (无效){执行
CGFloat的持续时间= 0.25;
*的UIViewController源= self.sourceViewController;
UIView的* BG = [source.view snapshotViewAfterScreenUpdates:YES];
bg.frame = UIScreen.mainScreen.bounds;
*的UIViewController DEST = self.destinationViewController;
UIView的*图标= [dest.view snapshotViewAfterScreenUpdates:YES];
icon.frame = self.iconFrame;
icon.alpha = 0.0;
[source.view addSubview:BG];
[source.view addSubview:图标];
[UIView的animateWithDuration:持续时间的动画:^ {
icon.alpha = 1.0F;
}];
[UIView的animateWithDuration:持续时间* 2动画:^ {
icon.frame = UIScreen.mainScreen.bounds;
bg.frame = [个体经营zoomedRect]
}完成:^(BOOL完){
[来源presentViewController:目标动画:NO完成:无];
[BG removeFromSuperview]
[图标removeFromSuperview]
}];} - (的CGRect)zoomedRect {
浮动屏幕宽度= UIScreen.mainScreen.bounds.size.width;
浮screenHeight = UIScreen.mainScreen.bounds.size.height; 浮动大小=屏幕宽度/ self.iconFrame.size.width;
浮动X =屏幕宽度/ 2 - (CGRectGetMidX(self.iconFrame)*大小);
浮Y = screenHeight / 2 - (CGRectGetMidY(self.iconFrame)*大小); 返回CGRectMake(X,Y,屏幕宽度*尺寸,screenHeight *大小);
}
我有一个的CGRect财产,iconFrame在SEGUE的.h文件。我从被附加到将被扩展的图标敲击手势识别进行SEGUE。你需要该图标的框架传递给SEGUE,这是我在源视图控制器的prepareForSegue方法做,
- (无效)prepareForSegue:(SpringboardSegue *)赛格瑞发件人:(UITapGestureRecognizer *){发件人
segue.iconFrame = sender.view.frame;
}
I am willing to create a segue animation similar to opening an app in iOS 7. Now I consider this approach: Non-segue implementation, but encountered an issue: if being implemented in custom segue, the code cannot resize viewcontroller's frame, which is principal part of the animation. As I can see, it applies viewcontroller's position, but cannot change it's size. Am I correct, that property viewcontroller.view.frame cannot be animated and has to remain constant and equal to size of the device's screen? I already implemented something similar with CGAffineTransformMakeScale
, but its a bit weird, so, I am looking for better solution. Below I paste the code I use for the segue.
#import "ZoomSegue.h"
#import "MiniMapViewController.h"
#import "InteractiveMapViewController.h"
@implementation ZoomSegue
- (void)perform {
InteractiveMapViewController *sourceViewController = self.sourceViewController;
MiniMapViewController *destinationViewController = self.destinationViewController;
destinationViewController.view.alpha = 0.0f;
destinationViewController.view.hidden = NO;
//Just to check, lets make view really small. Position it to the center we get from the segue.
destinationViewController.view.frame = CGRectMake(_originatingPoint.x, _originatingPoint.y, 60.0f, 60.0f);
[sourceViewController.view addSubview:destinationViewController.view];
float animationDuration = 1.5f;
[UIView animateWithDuration:animationDuration/2.0f animations:^{
destinationViewController.view.alpha = 1.0f;
}];
[UIView animateWithDuration:animationDuration animations:^{
//Just to check, lets make view very big. It does not work, although, the view goes to the upper left corner, so position works, but not the size
CGRect x = CGRectMake(0.0f, 0.0f, 9590.0f, 91366.0f);
destinationViewController.view.frame = x;
}];
}
@end
I don't know if you're correct, but a better way to do it anyway is to use a snapshot view. This code puts a small snapshot in the center of the screen then expands it to full size,
- (void)perform {
UIView *sourceView = ((UIViewController *)self.sourceViewController).view;
UIView *destinationView = [((UIViewController *)self.destinationViewController).view snapshotViewAfterScreenUpdates:YES];
destinationView.frame = CGRectMake(0, 0, 5, 5);
destinationView.center = CGPointMake(sourceView.center.x, sourceView.center.y);
[sourceView addSubview:destinationView];
[UIView animateWithDuration:1
animations:^{
destinationView.frame = sourceView.frame;
}
completion:^(BOOL finished) {
[[self sourceViewController] presentViewController:[self destinationViewController] animated:NO completion:nil];
}];
}
After Edit:
Here is a translation of the code in the link you provided that converts that animation into a segue,
-(void)perform {
CGFloat duration = .25;
UIViewController *source = self.sourceViewController;
UIView *bg = [source.view snapshotViewAfterScreenUpdates:YES];
bg.frame = UIScreen.mainScreen.bounds;
UIViewController *dest = self.destinationViewController;
UIView *icon = [dest.view snapshotViewAfterScreenUpdates:YES];
icon.frame = self.iconFrame;
icon.alpha = 0.0f;
[source.view addSubview:bg];
[source.view addSubview:icon];
[UIView animateWithDuration:duration animations:^{
icon.alpha = 1.0f;
}];
[UIView animateWithDuration:duration*2 animations:^{
icon.frame = UIScreen.mainScreen.bounds;
bg.frame = [self zoomedRect];
} completion:^(BOOL finished) {
[source presentViewController:dest animated:NO completion:nil];
[bg removeFromSuperview];
[icon removeFromSuperview];
}];
}
- (CGRect)zoomedRect {
float screenWidth = UIScreen.mainScreen.bounds.size.width;
float screenHeight = UIScreen.mainScreen.bounds.size.height;
float size = screenWidth / self.iconFrame.size.width;
float x = screenWidth/2 - (CGRectGetMidX(self.iconFrame) * size);
float y = screenHeight/2 - (CGRectGetMidY(self.iconFrame) * size);
return CGRectMake(x, y, screenWidth * size, screenHeight * size);
}
I have a CGRect property, iconFrame in the .h file of the segue. I performed the segue from a tap gesture recognizer that was attached to the icon that will be expanded. You need to pass the frame of that icon to the segue, which I do in the source view controller's prepareForSegue method,
-(void)prepareForSegue:(SpringboardSegue *)segue sender:(UITapGestureRecognizer *)sender {
segue.iconFrame = sender.view.frame;
}
这篇关于类似于iOS中7打开应用Segue公司动画:的ViewController框架是不可调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!