照片移动和缩放

http://www.cnblogs.com/liulunet/archive/2013/01/19/2866399.html


- (void)setSourceImage:(UIImage *)image{2if(sourceImage) {3[sourceImage release];4sourceImage =nil;5}6sourceImage =[image retain];7[_imageview setImage:self.sourceImage];8CGFloat wh = sourceImage.size.width/sourceImage.size.height;9CGSize displaySize;10if(wh >1) {//宽图11_imageContainer.maximumZoomScale = ((sourceImage.size.height / DEF_CUTSIZE >1)&&(sourceImage.size.height / DEF_CUTSIZE)*(DEF_CUTSIZE/DEF_HDSIZE) >1) ? (sourceImage.size.height / DEF_CUTSIZE)*(DEF_CUTSIZE/720) :1;//设置放大倍数12isImgAvailable = (sourceImage.size.height*2< DEF_CUTSIZE) ? NO : YES;//检查图片是否可用13displaySize = CGSizeMake(sourceImage.size.width*(DEF_CUTSIZE/sourceImage.size.height), DEF_CUTSIZE);14}else{//高图15_imageContainer.maximumZoomScale = ((sourceImage.size.width / DEF_CUTSIZE >1)&&(sourceImage.size.width / DEF_CUTSIZE)*(DEF_CUTSIZE/DEF_HDSIZE) >1) ? (sourceImage.size.width / DEF_CUTSIZE)*(DEF_CUTSIZE/720) :1;//设置放大倍数16isImgAvailable = (sourceImage.size.width*2< DEF_CUTSIZE) ? NO : YES;//检查图片是否可用17displaySize = CGSizeMake(DEF_CUTSIZE, sourceImage.size.height*(DEF_CUTSIZE/sourceImage.size.width));18}19_imageview.frame = CGRectMake(0,0, displaySize.width, displaySize.height);20_imageContainer.contentSize =_imageview.frame.size;21_imageContainer.contentInset = UIEdgeInsetsMake((SCREEN_HEIGHT - DEF_CUTSIZE)/2, (SCREEN_WIDTH - DEF_CUTSIZE)/2, (SCREEN_HEIGHT - DEF_CUTSIZE)/2, (SCREEN_WIDTH - DEF_CUTSIZE)/2);2223//让图片居中显示24_imageContainer.contentOffset = (wh>1) ? CGPointMake((displaySize.width - SCREEN_WIDTH)/2, _imageContainer.contentOffset.y) : CGPointMake(_imageContainer.contentOffset.x, (displaySize.height - SCREEN_HEIGHT)/2);25}

你可能感兴趣的:(照片移动和缩放)