TPCustomImageVIew.m 1 KB
Newer Older
n22's avatar
n22 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
//
//  TPCustomImageVIew.m
//  CNTaipingAgent
//
//  Created by 陈俊俊 on 15/1/28.
//  Copyright (c) 2015年 Taiping. All rights reserved.
//

#import "TPCustomImageVIew.h"

@interface TPCustomImageVIew()
@property (nonatomic,assign) id target;
@property (nonatomic,assign) SEL action;
@end

@implementation TPCustomImageVIew

- (id)initwithTarget:(id)target action:(SEL)action
{
    if (self == [super init]) {
        
        self.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapRecongnizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
        tapRecongnizer.numberOfTapsRequired  = 1;
        [self addGestureRecognizer:tapRecongnizer];
        
        self.target =target;
        self.action = action;
        
    }
    return self;
}

- (void)tap{
    //通过触摸当前的图片视图 让目标对象指向目标对象的行为
    if ([self.target respondsToSelector:self.action]) {
        [self.target performSelector:self.action withObject:self];
    }
}

@end