SingleScrollView.m 2.62 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 42 43 44 45 46
//
//  SingleScrollView.m
//  PhotoWallDemo
//
//  Created by LZXuan on 14-8-18.
//  Copyright (c) 2014年 LZXuan. All rights reserved.
//

#import "SingleScrollView.h"
#import "UIImageView+WebCache.h"
#define SW  1

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

@property (nonatomic,assign) id targetD;
@property (nonatomic,assign) SEL actionD;
@end
@implementation SingleScrollView
{
    UIImageView *_imageView;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        
    }
    return self;
}
- (SingleScrollView *)initWithFrame:(CGRect)frame image:(NSString *)image{
    if (self = [super initWithFrame:frame]) {
        self.showsHorizontalScrollIndicator = NO;
        self.showsVerticalScrollIndicator = NO;
        //设置最大放大倍数
        self.minimumZoomScale = 1.0;
        self.maximumZoomScale = 2.0;
        //粘贴一张图片
        _imageView = [[UIImageView alloc] init];
        
     
        _imageView.frame = CGRectMake(0, 0, self.frame.size.width - 10*2, self.frame.size.height);
47
        
n22's avatar
n22 committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
        _imageView.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
        if ([image hasPrefix:@"http://"]) {
            NSURL *url = [NSURL URLWithString:image];
            [_imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"leftDetailBg.png"]];
        }else{
            _imageView.image=[UIImage imageNamed:image];
        }
         _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
    }
    return self;
}
- (void)addSingleClickTarget:(id)target action:(SEL)action{
    self.target = target;
    self.action = action;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];

    tap.numberOfTapsRequired = 1;
    [self addGestureRecognizer:tap];
//    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]
//                                       initWithTarget:self action:@selector(pinch:)];
//    [self addGestureRecognizer:pinch];

    
}
- (void)tap:(UITapGestureRecognizer *)tap{
        if ([self.target respondsToSelector:self.action]) {
            [self.target performSelector:self.action withObject:self];
        }
}

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