2014-05-15 5 views
0

Я хочу создать слайдер UIImage, с возможностью увеличения изображения и проведите по другому изображению. Мои салфетки не распознаются, и я не знаю почему. Я использую какао-стручки, если вы знаете стручок, который это делает, пожалуйста, скажите мне. Или, можно ли использовать код iphone, в фотогалерее?NO распознаватель жестов uiimageview в ui scrollview

Это мой код:

- (void)viewDidLoad 
{ 


    [super viewDidLoad]; 
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 


    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; 
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; 

    [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; 
    [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight]; 
    [imgView setUserInteractionEnabled:YES]; 

    [imgView addGestureRecognizer:swipeLeft]; 
    [imgView addGestureRecognizer:swipeRight]; 


    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 
    manager.responseSerializer = [AFJSONResponseSerializer serializer]; 
    [manager GET:@"********************/test.json" parameters:nil success:^(AFHTTPRequestOperation *operation, NSArray *responseObject) { 
     //NSLog(@"URL"); 
     //NSLog(@"JSON: %@", responseObject); 


     urlArray = responseObject; 

     //NSLog(@" %@", urlArray); 
     int i=0; 

     url = [NSURL URLWithString:[urlArray objectAtIndex:i]]; 

     //NSLog(@"%@", url); 
     data = [NSData dataWithContentsOfURL:url]; 

     img = [[UIImage alloc] initWithData:data]; 



    [self.view setBackgroundColor:RGB(32,32,32)]; 

    if(orientation == UIInterfaceOrientationPortrait) { 
     UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-44)]; 
     scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     [self.view addSubview:scrollView]; 
     self.scrollView = scrollView; 


    if (img.size.width>img.size.height){ 
    //format d'images paysage 
     NSLog(@"PORTAIT image paysage"); 

     NSLog(@"%f", img.size.width); 
     NSLog(@"%f", img.size.height); 
     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width+img.size.height, self.scrollView.frame.size.height)]; 
     //imgView.contentMode = UIViewContentModeScaleAspectFit; 
     imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     [self.scrollView addSubview:imageView]; 
     self.scrollView.contentSize = imageView.frame.size; 
     self.imgView = imageView; 
     [self.imgView setImage:img]; 


    } 

    if (img.size.height>img.size.width && orientation == UIInterfaceOrientationPortrait){ 
     //format d'images portrait 
     NSLog(@"PORTAIT image portrait"); 
     NSLog(@"%f", img.size.width); 
     NSLog(@"%f", img.size.height); 
     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, img.size.height-img.size.width, self.scrollView.frame.size.height)]; 
     //imgView.contentMode = UIViewContentModeScaleAspectFit; 
     imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     [self.scrollView addSubview:imageView]; 
     self.scrollView.contentSize = imageView.frame.size; 
     self.imgView = imageView; 

    } 


     if (img.size.height==img.size.width){ 
      //format d'images portrait 
      NSLog(@"ICI %f", img.size.width); 
      NSLog(@"%f", img.size.height); 
      UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, img.size.width, self.scrollView.frame.size.height)]; 
      //imgView.contentMode = UIViewContentModeScaleAspectFit; 
      imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
      [self.scrollView addSubview:imageView]; 
      self.scrollView.contentSize = imageView.frame.size; 
      self.imgView = imageView; 

      [self.imgView setImage:img]; 

     } 

    } 


    } failure:nil]; 
} 


- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe { 

    if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) { 
     NSLog(@"Left Swipe"); 
    } 

    if (swipe.direction == UISwipeGestureRecognizerDirectionRight) { 
     NSLog(@"Right Swipe"); 
    } 

} 

ответ

0

В UISwipeGestureRecognizer s являются не срабатывает, потому что UIImageView вы присоединили их к тому, внутри UIScrollView. UIScrollView будет захватывать жесты, прежде чем UIImageView получит их.

Лучший способ сделать то, что вы предлагаете, чтобы поставить UIImageView внутри его собственной UIScrollView для масштабирования, как вы сделали, а затем положить каждый из UIScrollView-й в большем UIScrollView с pagingEnabled. Очевидно, вам придется сделать некоторые вычисления базового кадра, чтобы поместить UIScrollView в верхнюю часть UIScrollView и установить его contentSize.

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

+0

Большое спасибо. Можно ли использовать UiPageViewController с масштабированием? Я пытаюсь поместить свой scrollView1 в другой scrollViewTop и добавить салфетки на scrollViewTop, но это не сработает ... – Malicia

+0

Не добавляйте жестом салфетки ... Это свиток. Он будет прокручиваться. –

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