缩放

//
//  PinchView.m
//  ViewDemo
//
//  Created by wgd on 12-4-25.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "PinchView.h"
#import <QuartzCore/QuartzCore.h>


@implementation PinchView

@synthesize imageView;
@synthesize image;
@synthesize backView;
@synthesize showView;


-(PinchView *)initWithFrame:(CGRect)backRect andDest:(CGRect)destRect
{
   if (self = [super initWithFrame:backRect])
   {

       
        self.backView = [[UIView  alloc] initWithFrame:backRect];
        backView.backgroundColor = [UIColor grayColor];
        [self addSubview:backView];
        [backView release];
       
       self.imageView = [[UIImageView alloc] init];
       [self.backView addSubview:imageView];
       [imageView release];
        
        self.showView = [[UIView alloc] initWithFrame:destRect];
        [self addSubview:showView];
        [showView release];
       
       UIPinchGestureRecognizer *pinGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleSize:)];
       [showView addGestureRecognizer:pinGesture];
       [pinGesture release];
       
        
    
   }
    return self;
    
}

-(void)setImage:(UIImage *)image_
{
    if(image)
    {
        [image release];
        image = nil;
    }
    image = image_;
    [image_ retain];
    
    CGPoint centerPoint;
    centerPoint = self.showView.center;
    //imageView.center = centerPoint;
    //imageView.frame = CGRectMake(centerPoint.x-image.size.width/2,centerPoint.y-image.size.height/2,image.size.width, image.size.height);
    imageView.frame = CGRectMake(showView.frame.origin.x - backView.frame.origin.x,
                                 showView.frame.origin.y - backView.frame.origin.y,
                                 showView.frame.size.width,
                                 showView.frame.size.height);
    imageView.image = image;
    
}


-(void)dealloc
{
    [imageView release];
    [image release];
    [backView release];
    [showView release];
    [super dealloc];
}

#pragma mark -
#pragma mark scaleSize
-(void)scaleSize:(UIPinchGestureRecognizer *)pinGesture
{
//    NSLog(@"come");
    CGPoint locationInView = [pinGesture locationInView:imageView];
    //imageView.layer.anchorPoint = CGPointMake(locationInView.x/imageView.frame.size.width,locationInView.y/imageView.frame.size.height);
    //imageView.layer.anchorPoint = CGPointMake(0, 0);
    NSLog(@"anchorPoint x:%f y:%",imageView.layer.anchorPoint.x,imageView.layer.anchorPoint.y);
    if(imageView.frame.size.width <= 50 && [pinGesture scale] <1)
    {
        return;
    }
    
    if(imageView.frame.size.width >= imageView.image.size.width && [pinGesture scale] >1)
    {
        return;
    }
    
    imageView.transform = CGAffineTransformScale([imageView transform],
                                                  [pinGesture scale],
                                                  [pinGesture scale]);
    
}


@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值