objective-c - 如何使用 subview 对缩放 UIView 进行动画处理?

标签 objective-c ios cocoa-touch uiview uiviewanimation

此代码执行以下操作:它拍摄要消失的 NavigationController 的“快照”。然后快照被添加到容器 View Controller 的 View 中,滑开并显示新的 NavigationController。为了创建“弹出效果”,midAnFrame 使 View 比实际 View 稍大一些。之后postAnFrame提供了从容器 View 框架中滑出的功能。效果很好,唯一的问题是 animationContainer 的 subview 在动画过程中不会像其 superView 那样调整大小。

- (void)bringUpSettingsNavigationController {
CGFloat gradientWidth = 20;
CGFloat frameIncrease = 10;
CGRect preAnFrame  = CGRectMake(- gradientWidth, 0, self.view.frame.size.width + gradientWidth, self.view.frame.size.height);
CGRect midAnFrame  = CGRectMake(-(frameIncrease + gradientWidth), - frameIncrease, preAnFrame.size.width + (2*frameIncrease), preAnFrame.size.height + (2*frameIncrease));
CGRect postAnFrame = CGRectMake(midAnFrame.size.width, midAnFrame.origin.y, midAnFrame.size.width, midAnFrame.size.height);

UIView *animationContainer = [[UIView alloc]initWithFrame:preAnFrame];
animationContainer.backgroundColor = [UIColor clearColor];
animationContainer.autoresizesSubviews = YES;

self.topImageView = [[UIImageView alloc]initWithImage:[self topImageFromView:self.view]];
self.topImageView.frame = CGRectMake(gradientWidth, 0, preAnFrame.size.width - gradientWidth, preAnFrame.size.height);
[animationContainer addSubview:self.topImageView];
self.topImageView.clipsToBounds = YES;
UIView *gradientView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, gradientWidth, preAnFrame.size.height)];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = gradientView.bounds;
gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] CGColor], (id)[[UIColor colorWithWhite:0 alpha:.5] CGColor], nil];
gradientLayer.startPoint = CGPointMake(0, 0.5);
gradientLayer.endPoint = CGPointMake(1.0, 0.5);
[gradientView.layer insertSublayer:gradientLayer atIndex:0];
gradientView.backgroundColor = [UIColor clearColor];
[animationContainer addSubview:gradientView];
gradientView.clipsToBounds = YES;

[self.view addSubview:animationContainer];

BYSettingsNavigationController *settingsNavigationController = [[BYSettingsNavigationController alloc]initWithRootViewController:[[BYSettingsViewController alloc]init]];
[self addChildViewController:settingsNavigationController];
settingsNavigationController.view.frame = self.view.bounds;
[self.view insertSubview:settingsNavigationController.view belowSubview:animationContainer];
[settingsNavigationController didMoveToParentViewController:self];

[UIView animateWithDuration:0.2 animations:^{
    animationContainer.frame = midAnFrame;
} completion:^(BOOL finished) {
    [UIView animateWithDuration:.5 animations:^{
        animationContainer.frame = postAnFrame;
    } completion:^(BOOL finished) {
        [self.topImageView removeFromSuperview];
        [gradientView removeFromSuperview];
        self.topImageView = nil;
    }];
}];

[self.currentNavigationController willMoveToParentViewController:nil];
[self.currentNavigationController.view removeFromSuperview];
[self.currentNavigationController removeFromParentViewController];
}

check the lower right corner

预先感谢您的想法,祝您 2013 年一切顺利!

达里奥

最佳答案

你所做的不是放大,你只是改变框架大小。 要放大,您需要更改 View 的变换。

您需要做的是这样的事情:

view.transform = CGAffineTransformMakeScale(2.0, 2.0);

例如缩放 X2

关于objective-c - 如何使用 subview 对缩放 UIView 进行动画处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14172292/

相关文章:

objective-c - 如何从 Swift 指定与 Objective-C 中定义的接口(interface)同名的协议(protocol)

iOS UILabel 位置在调用 setText 时重置

ios - 如何在 Cordova 中播放 HTML5 视频时忽略铃声设置

iphone - Objective-C 中的二维数组?

ios - 如何确定具有角度的最近 CGPoint 和另一个 CGPoint

iphone - 如何通过键盘添加 UIView - iOS

iphone - 关闭我的应用程序 (OSX) 后继续收到 "This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation."

swift - 在 TableViewCell 中添加 CALayer 触发 CALayerInvalid Exception

ios - 从设备删除单个已发送的远程通知

ios - Deinit 未在 UIViewController 上调用,但 Dealloc 是