ipad实现ScrollView通过手势滚动和缩放的Image
2013-10-15 21:30
369 查看
在ipad上预览一张图片的时候,如果我们希望能够够缩放和滚动(类似与google地图效果),需要使用ScrollView
-------视图控制器定义如下
@interface TestBedViewController : UIViewController <UIScrollViewDelegate>
{
UIImage *weathermap;
}
@property (retain) UIImage *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 alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 284.0f)] autorelease];
sv.contentSize = self.weathermap.size;//要缩放的UIImage对象
sv.delegate = self; //设定代理对象
// 创建图片对象
UIImageView *iv = [[[UIImageView alloc] initWithImage:self.weathermap] autorelease];
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.minimumZoomScale = MIN(minzoomx, minzoomy); //最小缩放到当前ScrollView的大小比例
sv.maximumZoomScale = 3.0f; //最大缩放到图片的3倍
// 在scorllView添加image
[sv addSubview:iv];
[self.view addSubview:sv];
}
@end
-------视图控制器定义如下
@interface TestBedViewController : UIViewController <UIScrollViewDelegate>
{
UIImage *weathermap;
}
@property (retain) UIImage *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 alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 284.0f)] autorelease];
sv.contentSize = self.weathermap.size;//要缩放的UIImage对象
sv.delegate = self; //设定代理对象
// 创建图片对象
UIImageView *iv = [[[UIImageView alloc] initWithImage:self.weathermap] autorelease];
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.minimumZoomScale = MIN(minzoomx, minzoomy); //最小缩放到当前ScrollView的大小比例
sv.maximumZoomScale = 3.0f; //最大缩放到图片的3倍
// 在scorllView添加image
[sv addSubview:iv];
[self.view addSubview:sv];
}
@end
相关文章推荐
- ipad实现ScrollView通过手势滚动和缩放的Image
- ImageView通过matrix实现手势缩放
- Android实现 通过手势随意缩放、移动ImageView图片
- iPhone开发之UIScrollView滚动组件的使用(六)通过代理实现手势缩放——(拖线实现)
- 自定义Imageview控件实现多种手势操作 (拖动、水平缩放、竖直缩放、等比例缩放、双击、长按)
- 通过手势实现Android自定义View的缩放
- 【Android通过手势实现的缩放处理】
- 【Android通过手势实现的缩放处理】
- Android通过手势实现的缩放处理
- JAVA实现图像缩放(通过 java.awt.geom的仿射变换结合java.awt.image的各种插值方法实现)
- 实现ipad上的内嵌webview手势缩放图片(修改版,解决在第一张图片放大的情况下翻到下一张图片无法放大的问题) 基于Quo(js库)
- JAVA实现图像缩放(通过 java.awt.geom的仿射变换结合java.awt.image的各种插值方法实现)
- Android通过自定义ImageView控件实现图片的缩放和拖动的实现代码
- JAVA实现图像缩放(通过 java.awt.geom的仿射变换结合java.awt.image的各种插值方法实现)
- Android之实现手势缩放imageview中的图片
- Android实现 通过手势随意缩放、移动ImageView图片
- 通过ScrollView控制元素滚动效果以及背景图片平铺实现
- Android通过手势实现的缩放处理实例代码
- Android ImageView手势缩放完整的实现
- Android通过手势实现的缩放处理