Hi i am beginner in Ios and in my project i am adding one image on my View controller and when we click on this image then image need to zoom with full screen size for this i wrote some code but image is not fitting properly
According to my code screen is coming like below image but in want to fill that image entire screen help me
#import <UIKit/UIKit.h>
@interface ViewController1 : UIViewController<UIGestureRecognizerDelegate>
{
UITapGestureRecognizer *tap;
BOOL isFullScreen;
CGRect prevFrame;
}
@property (nonatomic, strong) UIImageView *imageView;
@end
#import "ViewController1.h"
@interface ViewController1 ()
@end
@implementation ViewController1
- (void)viewDidLoad
{
[super viewDidLoad];
isFullScreen = FALSE;
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgToFullScreen)];
tap.delegate = self;
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
_imageView.contentMode = UIViewContentModeScaleAspectFit;
[_imageView setClipsToBounds:YES];
_imageView.userInteractionEnabled = YES;
_imageView.image = [UIImage imageNamed:@"2.jpg"];
UITapGestureRecognizer *tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgToFullScreen:)];
tapper.numberOfTapsRequired = 1;
[_imageView addGestureRecognizer:tapper];
self.view.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:_imageView];
}
-(void)imgToFullScreen:(UITapGestureRecognizer*)sender {
if (!isFullScreen) {
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
prevFrame = _imageView.frame;
[_imageView setFrame:[[UIScreen mainScreen] bounds]];
}completion:^(BOOL finished){
isFullScreen = TRUE;
}];
return;
}
else{
[UIView animateWithDuration:0.5 delay:0 options:0 animations:^{
[_imageView setFrame:prevFrame];
}completion:^(BOOL finished){
isFullScreen = FALSE;
}];
return;
}
}
@end
you need to set all on tap-gesture. you need to expand imageviewsize on tapgesture. or change the size of width and height according to your view controllers full screen's height and with.
Here is Example of tapgesture .
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.