如何在iOS应用程序中使图像全屏显示[重复]
Posted
技术标签:
【中文标题】如何在iOS应用程序中使图像全屏显示[重复]【英文标题】:How to make an image go fullscreen in iOS app [duplicate] 【发布时间】:2013-06-05 10:21:41 【问题描述】:我是 xcode 和 Objective c 的新手,我想知道如何使用轻按手势使图像在触摸时全屏显示... 谁能帮帮我?
这是我尝试过的代码:
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view.
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tap.numberOfTapsRequired = 1;
tap.cancelsTouchesInView = NO;
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:tap];
-(void)handleTap
imageView.frame=CGRectMake(0,0,320,480);
【问题讨论】:
检查这个:-***.com/questions/9008975/… 不要忘记 imageView.contentMode = UIViewContentModeScaleToFill; 【参考方案1】:您可以更改图像视图的帧大小,然后它会自动进入全屏模式。
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture)];
tapGesture.numberOfTapsRequired=1;
[imageView setUserInteractionEnabled:YES];
[imageView addGestureRecognizer:tapGesture];
-(void)handleTapGesture
imageView.frame=CGRectMake(0,0,320,480);
【讨论】:
我刚收到这个错误信息:@autoreleasepool return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 你把这段代码保存在哪里? 我把它放在 ViewDidLoad [super viewDidLoad] 下 在您尝试过的问题中发布您的代码。 把@selector(handleTap:)中的冒号(:)去掉试试看。【参考方案2】:这个
// Detecting touches on your UIImageView
UITapGestureRecognizer *myImageViewTapped = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(changeFrameOfMyImage)];
myImageViewTapped.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:myImageViewTapped];
//...
//...
-(void)changeFrameOfMyImage
myImageView.frame = self.view.frame;
可能会成功!
【讨论】:
【参考方案3】: UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.cancelsTouchesInView = NO;
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:tapGesture];
-(void)handleTemplateTap:(UIGestureRecognizer *)sender
imageview.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
【讨论】:
谢谢!我要把什么放在哪里?我要在 .h 文件中写什么?以上是关于如何在iOS应用程序中使图像全屏显示[重复]的主要内容,如果未能解决你的问题,请参考以下文章
使用Android Navigation Component,如何使actionBar透明并在单个Fragment中使布局全屏?