iOS 7照片应用程序就像自定义UIViewController Transition

时间:2014-01-14 06:59:55

标签: ios iphone objective-c

我对iOS开发有点新意。我正在开发一个具有大约5,000个可视数据点的应用程序,按类别组织。我想用非常小的UICollectionViewCells在UICollectionView中呈现它们。当用户点击某个类别中的某些内容时,该类别会放大所选单元格的焦点。非常类似于iOS 7照片应用的“照片”标签的工作原理:年>收藏品>时刻。

如何实现这样的自定义转换?是否已经为完成此任务而编写了任何开源库?

1 个答案:

答案 0 :(得分:3)

如果找不到任何库,请尝试使用我为自定义动画编写的代码。您可以指定要缩放和缩放的视图的起点,终点,起始比例和结束比例。请参阅下面的示例我如何使用它。关键是使用假视图用动画推动它,然后在没有动画的情况下推送和弹出真实视图。 viewobj设置为从alpha 0到alpha 1淡入,zoomableView将从您作为参数提供的点/比例缩放到您在storyboard / xib中设置的最终位置。希望它会有所帮助。

@您可以创建一个类别vor UIView并添加这些方法

- (void) addSubView:(UIView*)viewObj animateFromPoint:(CGPoint)point zoomableView:(UIView*)view minScale:(CGSize)scale completion:(void (^)(void))completionBlock{
    CGPoint center = view.center;
    [view  setTransform:CGAffineTransformMakeScale(scale.width, scale.height)];
    viewObj.alpha = 0;
    view.center = point;

    [self addSubview:viewObj];
    [self addSubview:view];

    [UIView animateWithDuration:0.3
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         view.center = center;
                         [view  setTransform:CGAffineTransformMakeScale(1.0, 1.0)];
                         viewObj.alpha = 1;
                     }
                     completion:^(BOOL fin){
                         if(completionBlock)
                             completionBlock();
                     }];
}

- (void) removeFromSuperviewAnimateToPoint:(CGPoint)point zoomableView:(UIView*)view minScale:(CGSize)scale completion:(void (^)(void))completionBlock{
    CGRect startFrame = view.frame;
    self.alpha = 1;

    [self.superview addSubview:view];

    [UIView animateWithDuration:0.3
                          delay:0.0
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{
                         view.center = point;
                         [view  setTransform:CGAffineTransformMakeScale(scale.width, scale.height)];
                         self.alpha = 0;
                     }
                     completion:^(BOOL fin){

                         [self removeFromSuperview];
                         [view removeFromSuperview];
                         [view  setTransform:CGAffineTransformMakeScale(1, 1)];
                         view.frame = startFrame;
                         [self addSubview:view];

                         if(completionBlock)
                             completionBlock();
                     }];
}

并使用它们:

@你在索引路径上选择了项目:

            self.itemDetails = [self.storyboard instantiateViewControllerWithIdentifier:@"ItemDetailsVC"];
            ItemDetailsVC* itd = [self.storyboard instantiateViewControllerWithIdentifier:@"ItemDetailsVC"];
            __weak UIViewController* wself = self;
            [self.view addSubView:self.itemDetails.view animateFromPoint:self.zoomedFrom zoomableView:self.itemDetails.viewZoomable minScale:CGSizeMake(0.371134, 0.371134) completion:^{
                [wself.navigationController pushViewController:itd animated:NO];
            }];
self.addSubviewIsUp = YES;

您添加的视图的后退按钮:

        [self.navigationController popViewControllerAnimated:NO];

主屏幕的@ viewdidapear

if(self.addSubviewIsUp){
    [self.addVc.view removeFromSuperviewAnimateToPoint:CGPointMake(160, 75) zoomableView:self.addVc.zoomableView minScale:CGSizeMake(0.01, 0.01) completion:^{
    }];
}
self.addSubviewIsUp = NO;