我在viewDidLoad方法中使用下面的代碼。我期待圖像在被捏住時縮放,但不會縮放。UIImageview沒有得到放大
[self.displayImage setUserInteractionEnabled:YES];
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:@"imageUrl"];
NSLog(@"saved %@",savedValue);
_displayImage.image = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
NSData *data0 = [NSData dataWithContentsOfURL: [NSURL URLWithString:savedValue]];
UIImage *image = [UIImage imageWithData: data0];
dispatch_sync(dispatch_get_main_queue(), ^(void) {
_displayImage.image = image;
});
});
self.displayReceivedImageScrollView.delegate = self;
[self.displayReceivedImageScrollView addSubview:_displayImage];
_displayReceivedImageScrollView.contentSize = _displayImage.frame.size;
_displayReceivedImageScrollView.scrollEnabled = YES;
// For supporting zoom,
_displayReceivedImageScrollView.minimumZoomScale = 0.5;
_displayReceivedImageScrollView.maximumZoomScale = 2.0;
self.displayReceivedImageScrollView.contentOffset = CGPointMake(self.displayReceivedImageScrollView.bounds.size.width, 0);
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToLeftWithGestureRecognizer:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideToRightWithGestureRecognizer:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self.displayImage addGestureRecognizer:swipeLeft];
[self.displayImage addGestureRecognizer:swipeRight];
我在storyboard中添加了imageview。但我在運行期間爲了啓用縮放而擴大了滾動視圖。我無法縮放它。 swipeLeft或swipeRight方法永遠不會被調用。我怎樣才能解決這個問題?
爲什麼你用滑動手勢? –
我想放大它 – Learner