我的详细视图中有一个uiimageview,我想这样做,以便当我点击图像时,它会全屏打开图像。但是,我的代码似乎并没有起作用。知道我看起来做错了吗?
FullViewController.h
@interface FullArticleViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIGestureRecognizerDelegate>
{
IBOutlet UITapGestureRecognizer *tap;
IBOutlet UIScrollView *scroller;
IBOutlet UILabel *firstnameLabel;
IBOutlet UILabel *bodyLabel;
IBOutlet UILabel *descriptionLabel;
BOOL isFullScreen;
CGRect prevFrame;
}
FullViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
if ([[articleDetail objectForKey:@"ytID"] isEqualToString:@"none"]) {
featureImage.userInteractionEnabled = YES;
NSString *imageUrl = [NSString stringWithFormat:@"image/%@",cellImageLink];
[self.featureImage sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
[scroller setScrollEnabled:YES];
featureImage.userInteractionEnabled = YES;
[scroller bringSubviewToFront:featureImage];
UITapGestureRecognizer *tapgesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgToFullScreen)];
[tapgesture setNumberOfTapsRequired:1];
[featureImage addGestureRecognizer:tap];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
{
BOOL shouldReceiveTouch = YES;
if (gestureRecognizer == tap) {
shouldReceiveTouch = (touch.view == featureImage);
}
return shouldReceiveTouch;
}
-(void)imgToFullScreen{
if (!isFullScreen) {
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
//save previous frame
prevFrame = featureImage.frame;
[featureImage setFrame:[[UIScreen mainScreen] bounds]];
}completion:^(BOOL finished){
isFullScreen = true;
}];
return;
} else {
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
[featureImage setFrame:prevFrame];
}completion:^(BOOL finished){
isFullScreen = false;
}];
return;
}
}
编辑:请参阅上面更新的代码和下面的层次结构
答案 0 :(得分:1)
在viewDidLoad:
方法中尝试此操作:
[featureImage setUserInteractionEnables:YES];
UITapGestureRecognizer *tapgesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgToFullScreen)];
[tapgesture setNumberOfTapsRequired:1];
[featureImage addGestureRecognizer:tapgesture];