我想中心的圖像(相對於iPhone屏幕),使得當視圖加載時圖像是中心寬度/高度...在我的情況下,我的視圖加載在圖像本身的像素點0,0,如果我縮小圖像出現在左上角,而不是屏幕/視圖的中心。以下是我迄今爲止:如何以uiimageview/uiscrollview居中圖像(前後縮放)
UIImage *image = [UIImage imageNamed: @"t.bmp"];
self.view.backgroundColor = [UIColor blackColor];
self.mi.frame = CGRectMake(0, 0, image.size.width, image.size.height);
self.mi.contentMode = (UIViewContentModeCenter);
self.mi.backgroundColor = [UIColor blackColor];
[self.mi setImage:image];
/* Draw a line here!!
UIGraphicsBeginImageContext(self.mi.frame.size);
[self.mi.image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetLineWidth(context, 20.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0,0);
CGContextAddLineToPoint(context, 200, 200);
CGContextMoveToPoint(context, 200,0);
CGContextAddLineToPoint(context, 0, 200);
CGContextStrokePath(context);
self.mi.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
*/
self.expimg.maximumZoomScale = 2.0;
self.expimg.minimumZoomScale = 0.1;
self.expimg.clipsToBounds = YES;
self.expimg.delegate = self;
[self.expimg setContentSize:self.mi.frame.size];
[self.expimg addSubview: self.mi];
[self.view addSubview: self.expimg];
謝謝!
編輯:mi是UIImageView,expimg是UIScrollView(使用的接口生成器)。另外,定義了viewForZoomingInScrollView。
您的解決方案不工作,但我找到了答案:http://stackoverflow.com/questions/638299/uiscrollview-with-centered-uiimageview-like-照片 - 應用程序 順便說一句,在我的意見是正確的方式來畫一條線?它的工作只是想確保 – Alede