分享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;
}
else
scrollView.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;
}
关键词:
图片 适合屏幕 缩小放大引用irene40605级别: 骑士
UID: 12525
精华: 0
发帖: 183
可可豆: 1204 CB
威望: 1204 点
在线时间: 516(时)
注册时间: 2010-01-01
最后登录: 2015-08-04
发表于: 2011-08-26 10:08 发自: Web Page
很不错,有个新发现,谢谢吖
引用yanhong310级别: 圣骑士
UID: 83460
精华: 0
发帖: 385
可可豆: 3828 CB
威望: 3828 点
在线时间: 158(时)
注册时间: 2011-07-26
最后登录: 2013-01-31
发表于: 2011-08-26 10:20 发自: Web Page
mark
引用jueshizhenwo级别: 新手上路
UID: 12040
精华: 0
发帖: 10
可可豆: 91 CB
威望: 91 点
在线时间: 61(时)
注册时间: 2009-12-22
最后登录: 2015-07-10
发表于: 2011-12-15 14:11 发自: Web Page
mark 以后留着有用~~
引用edwardshang级别: 侠客
UID: 108614
精华: 0
发帖: 82
可可豆: 604 CB
威望: 604 点
在线时间: 44(时)
注册时间: 2011-11-29
最后登录: 2015-08-02
发表于: 2012-01-17 14:22 发自: Web Page
留爪留爪 mark
二着二着就二过了。
引用ugg级别: 侠客
UID: 13388
精华: 0
发帖: 117
可可豆: 1143 CB
威望: 1143 点
在线时间: 69(时)
注册时间: 2010-01-25
最后登录: 2014-05-01
发表于: 2012-03-11 23:35 发自: Web Page
mark,正在使用~
引用kuohuforever级别: 新手上路
UID: 128991
精华: 0
发帖: 5
可可豆: 50 CB
威望: 50 点
在线时间: 13(时)
注册时间: 2012-03-10
最后登录: 2012-05-17
发表于: 2012-03-12 21:24 发自: Web Page
O(∩_∩)O谢谢分享
引用西伯利亚狼级别: 侠客
UID: 67526
精华: 0
发帖: 128
可可豆: 753 CB
威望: 753 点
在线时间: 111(时)
注册时间: 2011-05-03
最后登录: 2015-08-04
发表于: 2012-03-13 10:19 发自: Web Page
留下 一个记号
引用vvyy级别: 侠客
UID: 59052
精华: 0
发帖: 58
可可豆: 391 CB
威望: 391 点
在线时间: 216(时)
注册时间: 2011-03-23
最后登录: 2015-07-23
发表于: 2012-05-16 15:32 发自: Web Page
引用tangyuting级别: 新手上路
状态:
未签到 - [3天]
UID: 287499
精华: 0
发帖: 1
可可豆: 37 CB
威望: 12 点
在线时间: 65(时)
注册时间: 2014-01-14
最后登录: 2015-03-18
发表于: 2015-02-03 16:48 发自: Web Page