HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ipad实现ScrollView通过手势滚动和缩放的Image大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

在ipad上预览一张图片的时候,如果我们希望能够够缩放和滚动(类似与google地图效果),需要使用ScrollView

-------视图控制器定义如下

@interface TESTBedViewController : UIViewController <UIScrollViewDelegate>

{

UIImage *weathermap;

}

@property (retainUIImage *weathermap;

@end


@implementation TESTBedViewController

@synthesize weathermap;

//在通过缩放手势的时候制定,所有ScrollView中的Image

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

{

return [self.view viewWithTag:201];

}


/*

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale

{

}

*/

- (void) viewDidLoad

{

// 创建滚动视图并设置大小和代理对象                                                        px    py   宽度 高度

UIScrollView *sv = [[[UIScrollView allocinitWithFrame:CGRectMake(0.0f0.0f320.0f284.0f)] autorelease];

sv.contentSize = self.weathermap.size;//要缩放的UIImage对象

sv.delegate = self; //设定代理对象

// 创建图片对象

UIImageView *iv = [[[UIImageView allocinitWithImage:self.weathermapautorelease];

iv.userInteractionEnabled = YES;

iv.tag = 201;

// 计算缩放数值

float minzoomx = sv.frame.size.width / self.weathermap.size.width;

float minzoomy = sv.frame.size.height / self.weathermap.size.height;

sv.@H_552_27@minimumZoomScale = @H_79_259@mIN(minzoomx,minzoomy);  //最小缩放到当前ScrollView的大小比例

sv.@H_836_8@maximumZoomScale = 3.0f; //最大缩放到图片的3倍

// 在scorllView添加image

[sv addSubview:iv];

[self.view addSubview:sv];

}

@end

@H_179_301@

大佬总结

以上是大佬教程为你收集整理的ipad实现ScrollView通过手势滚动和缩放的Image全部内容,希望文章能够帮你解决ipad实现ScrollView通过手势滚动和缩放的Image所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。