2013-02-04 40 views

回答

1

使用後在scrollViewDidEndZooming代碼..可能對你有幫助:)

- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize { 
     CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height)); 
     CGImageRef imageRef = image.CGImage; 

     UIGraphicsBeginImageContextWithOptions(newSize, NO, 0); 
     CGContextRef context = UIGraphicsGetCurrentContext(); 

     // Set the quality level to use when rescaling 
     CGContextSetInterpolationQuality(context, kCGInterpolationHigh); 
     CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height); 

     CGContextConcatCTM(context, flipVertical); 
     // Draw into the context; this scales the image 
     CGContextDrawImage(context, newRect, imageRef); 

     // Get the resized image from the context and a UIImage 
     CGImageRef newImageRef = CGBitmapContextCreateImage(context); 
     UIImage *newImage = [UIImage imageWithCGImage:newImageRef]; 

     CGImageRelease(newImageRef); 
     UIGraphicsEndImageContext();  

     return newImage; 
    } 
0

您可以使用下面的代碼:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale { 
    CGSize nowSize = view.frame.size; 
    if (nowSize.height >= self.myScrollView.frame.size.height) 
     self.myScrollView.contentInset = UIEdgeInsetsZero; 
    else { 
     CGFloat delta = self.myScrollView.frame.size.height/2 - view.frame.size.height/2; 
     self.myScrollView.contentInset = UIEdgeInsetsMake(delta, 0, delta, 0); 
    } 
}