分享UIScrollView显示适合屏幕大小图片及缩小放大程序 - (void)viewDidLoad { [super viewDidLoad];//[super viewDidLoad];UIImage *image = [UIImage imageNamed:@"ipod.jpg"];imageView = [[UIImageView alloc] initWithImage:image];scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];if(image.size.width > 320){imageView.frame = CGRectMake(0, 0, 320, image.size.height*(320/image.size.width));scrollView.contentSize = CGSizeMake(320, image.size.height*(320/image.size.width));//image.size;}else if(image.size.height > 460){imageView.frame = CGRectMake(0, 0, image.size.width*(460/image.size.height), 460);scrollView.contentSize = CGSizeMake(image.size.width*(460/image.size.height), 460);//image.size;}elsescrollView.contentSize = image.size; [scrollView addSubview:imageView];scrollView.bounces = NO;scrollView.minimumZoomScale = 0.3;scrollView.maximumZoomScale = 3.0;scrollView.delegate = self;//[window addSubview:scrollView];[self.view addSubview:scrollView];}//*/ ///*// Override to allow orientations other than the default portrait orientation.- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {// Return YES for supported orientations.return YES;}//*////*- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration{UIInterfaceOrientation toOrientation = self.interfaceOrientation;if(toOrientation == UIInterfaceOrientationPortrait || toOrientation == UIInterfaceOrientationPortraitUpsideDown){//self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 3, scrollView.frame.size.height); scrollView.frame = CGRectMake(0, 0, 320, 460); }else {scrollView.frame = CGRectMake(0, 0, 480, 300);}}- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{return imageView;} |