[英]Zoom into cell on selection with UICollectionView
I have a grid of images that are handled by a UICollectionView. 我有一个由UICollectionView处理的图像网格。 What I would like to do is transition to another View Controller on selection of a cell by zooming into the image and have that image take up a large portion of the screen in the child View Controller.
我想要做的是通过放大图像转换到另一个视图控制器选择一个单元格,并让该图像占据子视图控制器中的大部分屏幕。 Is there any good way of creating this behavior.
有没有什么好方法可以创建这种行为。
Thanks for all the help! 感谢您的帮助!
In Child view controller You can add a scroll view and can add property like that. 在子视图控制器中您可以添加滚动视图,并可以添加这样的属性。
scrollView.bouncesZoom = YES;
scrollView.delegate = self;
scrollView.clipsToBounds = YES;
Add an image view :- 添加图片视图: -
imageView = [[UIImageView alloc] initWithImage:[UIImage imgnamed:@"image01.png"]];
imageView.userIntractionEnabled = YES;
imageView.autoSizingMask = UIViewAutoresizingFlexibleWidth;
[scrollview addSubView:imageView];
Calculate minimum scale zoom level :- 计算最小比例缩放级别: -
float minimumScale = [scrollView frame].size.width / [imageView frame].size.width;
scrollView.maximumZoomScale = 3.0 // you can exeed as per your requirment
scrollView.minimumZoomScale = minimumScale;
scrollView.zoomScale = minimumScale;
Hope this help you. 希望这对你有所帮助。 If Any question or problem then ask in comments.
如果有任何疑问或问题,请在评论中提问。
For this, I would use a custom segue. 为此,我会使用自定义segue。 In the UICollectionView documentation, Apple recommends using a fake cell when moving it across your CollectionView.
在UICollectionView文档中,Apple建议在CollectionView中移动它时使用假单元格。 You can do this with storyboard or programatically.
您可以使用故事板或以编程方式执行此操作。 Inside your -prepareForSegue: method, place the image from the selected cell on the screen centered over the cell, then animate the scaling in the segue.
在-prepareForSegue:方法中,将屏幕上选定单元格的图像置于单元格的中心,然后在segue中设置缩放比例。
Custom Segue guide: https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomSegues/CreatingCustomSegues.html Custom Segue指南: https : //developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomSegues/CreatingCustomSegues.html
Ray's site is also boss: http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2 Ray的网站也是老板: http : //www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.