0
任何有關如何在使用UIScrollView時保持png或jpg質量的建議? 當我放大我的圖片,他們得到的所有失焦...png或jpg在UIScrollView中使用變焦時質量鬆動
任何有關如何在使用UIScrollView時保持png或jpg質量的建議? 當我放大我的圖片,他們得到的所有失焦...png或jpg在UIScrollView中使用變焦時質量鬆動
使用後在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;
}
您可以使用下面的代碼:
- (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);
}
}