.本框架可以快速集成图片过渡转场动画,目前有push和modal两种方式,呈现方式为zoom放大动画效果.
/**
* 使用默认的方式,导入头文件 FYTransitionController.h
* 创建一个继承自 FYTransitionController 的子类控制器即可
*/
@interface ImageViewController : FYTransitionController
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@end
UIImageView *oImageView = [[UIImageView alloc] initWithImage:cell.imageView.image];
oImageView.frame =[cell.imageView convertRect:cell.imageView.frame toView:self.view];
ImageViewController *imageVC = [[ImageViewController alloc] initWithOriginalImageView:oImageView];
imageVC.view.backgroundColor = [UIColor darkGrayColor];
//一定得设置代理,不然自动转场动画无法生效
imageVC.transitioningDelegate = imageVC;
[self presentViewController:imageVC animated:YES completion:^{
imageVC.titleLabel.text = cell.label.text;
}];
/**
* 导入头文件 FYTransitionController.h
* 创建一个继承自 FYTransitionController 的子类控制器,并且遵守 FYTransitionProtocol 协议
*/
@interface CustomViewController : FYTransitionController <FYTransitionProtocol>
@end
/**
* 返回imageView的位置,需要特别注意的是,如果使用xib布局的话,不能直接返回控件的frame,
* 因为控件还未初始化,所以在这里得用代码设置imageView的位置
*
* @return 返回imageView在其父控件的frame
*/
- (CGRect)fy_transitionFinalImageViewFrame{
return CGRectMake(10, 65, 300, 300);
}
/**
* 动画完成后的回调,获得最终imageView,在此回调中将imageView添加到父控件中,
* 在下面的方法中没有添加 imageView 的相关代码是因为使用了xib,直接赋值就好了
*
* @param imageView 回调传值
*/
- (void)fy_transitionCompleteAnimateImageView:(UIImageView *)imageView{
self.mainImageView.image = imageView.image;
self.mainImageView.backgroundColor = [UIColor greenColor];
self.mainImageView.userInteractionEnabled = YES;
self.mainImageView.clipsToBounds = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapFinalImageView:)];
[self.mainImageView addGestureRecognizer:tapGesture];
}
- (void)tapFinalImageView:(UITapGestureRecognizer *)tapGesture{
if (self.navigationController.delegate == self) {
[self.navigationController popViewControllerAnimated:YES];
} else if (self.transitioningDelegate == self) {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
UIImageView *oImageView = [[UIImageView alloc] initWithImage:cell.imageView.image];
oImageView.frame =[cell.imageView convertRect:cell.imageView.frame toView:self.view];
ImageViewController *imageVC = [[ImageViewController alloc] initWithOriginalImageView:oImageView];
//一定得设置代理,不然自动转场动画无法生效
self.navigationController.delegate = imageVC;
[self.navigationController pushViewController:imageVC animated:YES];
.目前正在研发更好的实现方式,更新中...