2013-03-25 3 views
13

Сначала я подключаю UISwipeGestureRecognizer к представлению изображения, метод действия не может быть запущен. Затем я присоединяю UISwipeGestureRecognizer для просмотра представления контроллера, он работает хорошо. Я не знаю, почему , вот код, который не работаетраспознаватель жестов не работает на subview

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    UISwipeGestureRecognizer *swipeRight=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction)]; 
    swipeRight.direction=UISwipeGestureRecognizerDirectionRight; 
    //imageView is an outlet of image view 
    [imageView addGestureRecognizer:swipeRight]; 
} 

вот код, который хорошо работает

- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view. 

    UISwipeGestureRecognizer *swipeRight=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction)]; 
    swipeRight.direction=UISwipeGestureRecognizerDirectionRight; 
    //imageView is an outlet of image view 
    [self.view addGestureRecognizer:swipeRight]; 
} 

ответ

25

Добавьте этот код в ImageView:

imageView.userInteractionEnabled = YES; 
+0

Amazing.It хорошо работает. Большое вам спасибо. –

2

Попробуйте один [imageView setUserInteractionEnabled:YES];

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