2017-02-03 2 views
0

Я говорю 10 изображений, которые я должен изменить, прокручивая или прокручивая и использую двойное нажатие для увеличения в определенном положении, и кастрюля будет работать, когда изображение будет увеличено иначе, а бок о бок жест жестки должен быть поддерживается.Все жесты в массиве изображения

Для этого я применяю логику, но есть конфликт между салфеткой и жесты панорамы, поэтому я бросаю концепцию салфетки, я использую scrollview, а изображение просматривается внутри, но когда одно изображение увеличено и я прокручиваю по горизонтали, следующее изображение также увеличивается.

Хотя я поставил условие, чтобы получить изображение на том же самом размере в scrollview, прокрутил, но не получило работу.

Я использовал просмотр коллекции и внутри ячейки. Я разместил scrollview, затем изображение и применил все жесты, но не буду работать.

+0

намек: установить делегат и и реализовать 'методы делегата UIGestureRecognizer'. –

+0

Попробуйте CollectionView. Вот пример: http://stackoverflow.com/questions/33546395/is-possible-to-zoom-in-out-a-uiimageview-in-custom-cell-of-a-uicollectionview-on – krishnanunni

+0

Я попробовал этот код, но его не работает. Подразумевается также .. @ krishnanunni –

ответ

0

Согласно krishnanunni ответила ссылке From: «is possible to zoom in/out a UIImageView in custom cell of a UICollectionView only when pinch the cell's imageView?» .Я модифицированный бит и работает хорошо Arrangement Same as from Sample

in gallerycell.m 

@property (weak, nonatomic) IBOutlet UIScrollView *scrollview; 
@property (weak, nonatomic) IBOutlet UIImageView *imageview; 

- (void)setup; 

@end 


//cell.m 

#import "Cell.h" 
#define MAXIMUM_SCALE 3.0 
#define MINIMUM_SCALE 1.0 

@interface Cell()<UIScrollViewDelegate> 

@end 

@implementation Cell 


- (void)setup { 

    CGFloat newScale = MINIMUM_SCALE; 
    CGAffineTransform transform = CGAffineTransformMakeScale(newScale, newScale); 
    self.imgView.transform = transform; 
    self.scrView.contentSize = self.imgView.frame.size; 

    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)]; 
    doubleTap.delegate = self; 
    [self.scrView addGestureRecognizer:doubleTap]; 
    [doubleTap setNumberOfTapsRequired:2]; 
    ZoomCheck = YES; 


    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(zoomImage:)]; 
    pinch.delegate = self; 
    self.imgView.gestureRecognizers = @[pinch]; 
    self.imgView.userInteractionEnabled = YES; 
    self.scrView.delegate = self; 

} 

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { 
    return self.imgView; 
} 
- (void)scrollViewDidZoom:(UIScrollView *)scrollView { 
    // The scroll view has zoomed, so we need to re-center the contents 
    [self centerScrollViewContents]; 
} 

- (void)centerScrollViewContents { 
    // This method centers the scroll view contents also used on did zoom 
    CGSize boundsSize = self.scrView.bounds.size; 
    CGRect contentsFrame = self.imgView.frame; 

    if (contentsFrame.size.width < boundsSize.width) { 
     contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width)/2.0f; 
    } else { 
     contentsFrame.origin.x = 0.0f; 
    } 

    if (contentsFrame.size.height < boundsSize.height) { 
     contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height)/2.0f; 
    } else { 
     contentsFrame.origin.y = 0.0f; 
    } 

    self.imgView.frame = contentsFrame; 
} 


- (void)handleDoubleTap:(UITapGestureRecognizer *)gesture { 
    NSLog(@"TAPCALLED"); 
    CGPoint location = [gesture locationInView:self.imgView]; 
    NSLog(@"x %f y %f",location.x, location.y); 
    CGFloat currentScale = self.frame.size.width/self.bounds.size.width; 

    NSLog(@"%.f",currentScale); 
    CGPoint pointInView = [gesture locationInView:self.imgView]; 
    if(ZoomCheck){ 

     // Get a zoom scale that's zoomed in slightly, capped at the maximum zoom scale specified by the scroll view 
     CGFloat newZoomScale = self.scrView.zoomScale * 3.0f; 
     newZoomScale = MIN(newZoomScale, self.scrView.maximumZoomScale); 

     // Figure out the rect we want to zoom to, then zoom to it 
     CGSize scrollViewSize = self.scrView.bounds.size; 

     CGFloat w = scrollViewSize.width/newZoomScale; 
     CGFloat h = scrollViewSize.height/newZoomScale; 
     CGFloat x = pointInView.x - (w/2.0f); 
     CGFloat y = pointInView.y - (h/2.0f); 

     CGRect rectToZoomTo = CGRectMake(x, y, w, h); 

     [self.scrView zoomToRect:rectToZoomTo animated:YES]; 


     ZoomCheck=NO; 
    } 
    else{ 

     CGFloat newZoomScale = self.scrView.zoomScale/3.0f; 
     newZoomScale = MIN(newZoomScale, self.scrView.minimumZoomScale); 

     // Figure out the rect we want to zoom to, then zoom to it 
     CGSize scrollViewSize = self.scrView.bounds.size; 

     CGFloat w = scrollViewSize.width * newZoomScale; 
     CGFloat h = scrollViewSize.height * newZoomScale; 
     CGFloat x = pointInView.x - (w * 2.0f); 
     CGFloat y = pointInView.y - (h * 2.0f); 

     CGRect rectToZoomTo = CGRectMake(x, y, w, h); 

     [self.scrView zoomToRect:rectToZoomTo animated:YES]; 


     ZoomCheck=YES; 
    } 


} 

//----------------------------------------------------------------------- 

#pragma mark - Custom Methods 

- (void)zoomImage:(UIPinchGestureRecognizer *)gesture { 

    if (UIGestureRecognizerStateBegan == gesture.state || 
     UIGestureRecognizerStateChanged == gesture.state) { 

     // Use the x or y scale, they should be the same for typical zooming (non-skewing) 
     float currentScale = [[gesture.view.layer valueForKeyPath:@"transform.scale.x"] floatValue]; 

     // Variables to adjust the max/min values of zoom 
     float minScale = 1.0; 
     float maxScale = 3.0; 
     float zoomSpeed = .5; 

     float deltaScale = gesture.scale; 

     // You need to translate the zoom to 0 (origin) so that you 
     // can multiply a speed factor and then translate back to "zoomSpace" around 1 
     deltaScale = ((deltaScale - 1) * zoomSpeed) + 1; 

     // Limit to min/max size (i.e maxScale = 2, current scale = 2, 2/2 = 1.0) 
     // A deltaScale is ~0.99 for decreasing or ~1.01 for increasing 
     // A deltaScale of 1.0 will maintain the zoom size 
     deltaScale = MIN(deltaScale, maxScale/currentScale); 
     deltaScale = MAX(deltaScale, minScale/currentScale); 

     CGAffineTransform zoomTransform = CGAffineTransformScale(gesture.view.transform, deltaScale, deltaScale); 
     gesture.view.transform = zoomTransform; 

     // Reset to 1 for scale delta's 
     // Note: not 0, or we won't see a size: 0 * width = 0 
     gesture.scale = 1; 
    } 

    } 


@end 

Примечание: Zoomcheck является BOOL, чтобы проверить, если он doubletapped и масштаба ранее.

Добавить UICollectionView И внутри клетки добавить Scrollview и затем imageview.the расположение показано в ссылке выше

0

Попробуйте использовать делегаты прокрутки. Не используйте жест жесты только для использования двойного крана трансфокатора и салфетки. Он работает нормально.

+0

, что я знаю, но я тоже не буду кастом. Помогите мне с этим –

+0

Приглашенные представители прокрутки помогут вам также панорамировать. Использовать - (UIView *) viewForZoomingInScrollView: (UIScrollView *) scrollView { return yourImageView; } –

Смежные вопросы