Help us understand the problem. What is going on with this article?

UIScrollViewに追加したUIImageViewのタッチイベントを取得する

More than 5 years have passed since last update.

UIScrollViewにカテゴリとして追加する。
タッチされたら次のレスポンダーへ渡す

UIScrollView+TouchEvent.h
#import <UIKit/UIKit.h>

@interface UIScrollView (UIScrollView_TouchEvent)
@end
UIScrollView+TouchEvent.m
#import "UIScrollView+UIScrollView_TouchEvent.h"

@implementation UIScrollView (UIScrollView_TouchEvent)

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [[self nextResponder] touchesBegan:touches withEvent:event];
}

@end

下記ファイルに追加することでプロジェクト全体で利用出来る。

hoge-Prefix.pch
#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>
    #import "UIScrollView+UIScrollView_TouchEvent.h"
#endif

使う箇所でタッチイベントをYESに設定する。

HogeViewController.m
        imageView.userInteractionEnabled = YES;
Potof_
週末プログラマーZ
http://potof.net/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away