67 lines
1.3 KiB
Objective-C
67 lines
1.3 KiB
Objective-C
//
|
|
// LYPhoto.m
|
|
// PhotoShow
|
|
//
|
|
// Created by 米明 on 16/3/4.
|
|
// Copyright © 2016年 LY. All rights reserved.
|
|
//
|
|
|
|
#import "LYPhoto.h"
|
|
|
|
@interface LYPhoto ()
|
|
|
|
@property (nonatomic,assign) id target;
|
|
@property (nonatomic,assign) SEL action;
|
|
@property (nonatomic,strong) UITapGestureRecognizer * tapPress;
|
|
|
|
@end
|
|
|
|
@implementation LYPhoto
|
|
|
|
- (instancetype)init{
|
|
self = [super init];
|
|
if(self){
|
|
[self setUp];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame{
|
|
self = [super initWithFrame:frame];
|
|
if(self){
|
|
[self setUp];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)setUp{
|
|
self.contentMode = UIViewContentModeScaleToFill;
|
|
}
|
|
|
|
- (UITapGestureRecognizer *)tapPress{
|
|
if (!_tapPress) {
|
|
_tapPress = [[UITapGestureRecognizer alloc]init];
|
|
[_tapPress addTarget:self action:@selector(tapAction:)];
|
|
}
|
|
return _tapPress;
|
|
}
|
|
|
|
- (void)tapAction:(id)sender{
|
|
|
|
if ([self.target respondsToSelector:self.action]) {
|
|
[self.target performSelector:self.action withObject:self];
|
|
}
|
|
|
|
}
|
|
|
|
- (void)addTarget:(id)target action:(SEL)action{
|
|
//打开用户交互接口
|
|
|
|
[self addGestureRecognizer:self.tapPress];
|
|
self.userInteractionEnabled = YES;
|
|
self.target = target;//目标对象
|
|
self.action = action;//目标对象行为
|
|
}
|
|
@end
|