我被困于在点击UICollectionViewController中的单元格时呈现完整的图像 [英] I am stuck at presenting a full image on tapping the cell in UICollectionViewController
问题描述
我的应用程序中有一个UICollectionViewController
,我希望在用户点击图像时在一个特定大小的特定单元格中制作图像.
I have a UICollectionViewController
in my application and I wish to make the image in a particular cell of full size when the user taps on it.
很抱歉给您带来麻烦,因为我是iOS的初学者.据我所知,它将以新的View controller
呈现,如果是/否,那么如何?
Sorry for the hassle, as I am a beginner for iOS. As per my knowledge will it be presented in a new View controller
and if yes/no, then how?
谢谢.
推荐答案
如果使用情节提要,只需将新的ViewController添加到场景中,然后从CollectionView单元格Ctrl-拖动到ViewController即可创建序列.如果要全屏,请选择模式.
If using storyboard, just add new ViewController to the scene and Ctrl-drag from the CollectionView cell to the ViewController to create segue. Choose modal if you want full screen.
在CollectionViewController类中,您需要将图像引用传递给Detail ViewController的属性.您需要使用公共属性,因为当detailVC加载时,尚未设置图像的插座.实例化之后,您只需将图像设置为插座"即可显示它.
In your CollectionViewController class, you need to pass the image reference to a property of the Detail ViewController. You need to use a public property, as the Outlet for the image is not set yet when the detailVC loads. After its instantiated, you just set the image to the Outlet to display it.
MyCVC.m(UICollectionViewController的子类)
#import "MyCVC.h"
#import "DetailVC.h"
@interface MyCVC ()
@end
@implementation MyCVC
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"detailSegue"] && [segue.destinationViewController isKindOfClass:[DetailVC class]]) {
DetailVC *detailVC = segue.destinationViewController;
detailVC.image = sender.image; // or any other reference to the actual image to display
}
}
@end
DetailVC.h
#import <UIKit/UIKit.h>
@interface DetailVC : UIViewController
@property (strong, nonatomic) UIImage *image;
@end
DetailVC.m
#import "DetailVC.h"
@interface DetailVC ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation DetailVC
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.imageView.image = self.image;
}
@end
这篇关于我被困于在点击UICollectionViewController中的单元格时呈现完整的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!