2

这段代码执行以下操作:它需要一个 NavigationController 的“快照”,它意味着要消失。然后将快照添加到容器视图控制器的视图中,滑开并显示新的 NavigationController。为了创建“弹出效果”,midAnFrame使视图比实际视图大一点。之后postAnFrame提供了从容器视图的框架中滑出的功能。效果很好,唯一的问题是动画容器的子视图在动画期间不会像它们的 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];
}

检查右下角

提前感谢您的想法,祝您 2013 年愉快!

达里奥

4

1 回答 1

2

你所做的不是放大,你只是改变帧大小。要放大,您需要更改视图的转换。

你需要做的是沿着这条线:

view.transform = CGAffineTransformMakeScale (2.0 , 2.0);

例如缩放 X2

于 2013-01-05T15:02:06.117 回答