分享

主题 : 分享UIScrollView显示适合屏幕大小图片及缩小放大程序

 没原创_去搜索 2015-08-05

分享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;
}

级别: 骑士
UID: 12525
精华: 0 
发帖: 183
可可豆: 1204 CB
威望: 1204 点
在线时间: 516(时)
注册时间: 2010-01-01
最后登录: 2015-08-04
沙发 :发表于: 2011-08-26 10:08   发自: Web Page
很不错,有个新发现,谢谢吖 
级别: 圣骑士
UID: 83460
精华: 0 
发帖: 385
可可豆: 3828 CB
威望: 3828 点
在线时间: 158(时)
注册时间: 2011-07-26
最后登录: 2013-01-31
板凳 :发表于: 2011-08-26 10:20   发自: Web Page
mark 
级别: 新手上路
UID: 12040
精华: 0 
发帖: 10
可可豆: 91 CB
威望: 91 点
在线时间: 61(时)
注册时间: 2009-12-22
最后登录: 2015-07-10
3 楼: 发表于: 2011-12-15 14:11   发自: Web Page
mark 以后留着有用~~ 
级别: 侠客
UID: 108614
精华: 0 
发帖: 82
可可豆: 604 CB
威望: 604 点
在线时间: 44(时)
注册时间: 2011-11-29
最后登录: 2015-08-02
4 楼: 发表于: 2012-01-17 14:22   发自: Web Page
留爪留爪 mark 
二着二着就二过了。
级别: 侠客
UID: 13388
精华: 0 
发帖: 117
可可豆: 1143 CB
威望: 1143 点
在线时间: 69(时)
注册时间: 2010-01-25
最后登录: 2014-05-01
5 楼: 发表于: 2012-03-11 23:35   发自: Web Page
mark,正在使用~ 
级别: 新手上路
UID: 128991
精华: 0 
发帖: 5
可可豆: 50 CB
威望: 50 点
在线时间: 13(时)
注册时间: 2012-03-10
最后登录: 2012-05-17
6 楼: 发表于: 2012-03-12 21:24   发自: Web Page
O(∩_∩)O谢谢分享 
级别: 侠客
UID: 67526
精华: 0 
发帖: 128
可可豆: 753 CB
威望: 753 点
在线时间: 111(时)
注册时间: 2011-05-03
最后登录: 2015-08-04
7 楼: 发表于: 2012-03-13 10:19   发自: Web Page
留下 一个记号 
级别: 侠客
UID: 59052
精华: 0 
发帖: 58
可可豆: 391 CB
威望: 391 点
在线时间: 216(时)
注册时间: 2011-03-23
最后登录: 2015-07-23
8 楼: 发表于: 2012-05-16 15:32   发自: Web Page
   
级别: 新手上路
状态: 未签到 - [3天]
UID: 287499
精华: 0 
发帖: 1
可可豆: 37 CB
威望: 12 点
在线时间: 65(时)
注册时间: 2014-01-14
最后登录: 2015-03-18
9 楼: 发表于: 2015-02-03 16:48   发自: Web Page
 


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多