CrazyBoy 稍嫌羞澀的路人
註冊時間: 2011-08-23 文章: 2
61.14 果凍幣
|
發表於: 2011-8-23, PM 6:26 星期二 文章主題: 如何利用UIScrollView和UIImageView進行圖片放大和縮小 |
|
|
ZoomViewController.h:
代碼: |
#import <uikit /UIKit.h>
@interface ZoomViewController : UIViewController <uiscrollviewdelegate> {
IBOutlet UIScrollView *scroll;
UIImageView *image;
}
@property (nonatomic, retain) UIScrollView *scroll;
@end
|
ZoomViewController.m:
代碼: |
#import "ZoomViewController.h"
@implementation ZoomViewController
@synthesize scroll;
- (void)viewDidLoad {
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img_body.png"]];
scroll.contentSize = image.frame.size;
[scroll addSubview:image];
scroll.minimumZoomScale = 0.4;
scroll.maximumZoomScale = 4.0;
scroll.delegate = self;
[scroll setZoomScale:scroll.minimumZoomScale];
[super viewDidLoad];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return image;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
|
部分注釋已刪除,有不明白再問我. |
|