在iPhone中实现图片缩放

来源:互联网 发布:网络侦探贝尔菲兽 编辑:程序博客网 时间:2024/05/01 11:25
如果想实现通过手势对UIImage进行缩放,可以参考下面的代码。(非官方SDK) 下面的代码是Erica Sadun的例子: id scroller = [[UIScroller alloc] initWithFrame :CGRectMake( 0.0f , 0.0f , 320.0f , 480.0f )]; [s
  

如果想实现通过手势对UIImage进行缩放,可以参考下面的代码。(非官方SDK)

下面的代码是Erica Sadun的例子:

 

 

id scroller = [[UIScroller alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];

[scroller setAllowsFourWayRubberBanding:YES];

[scroller setAdjustForContentSizeChange:YES];

[scroller setThumbDetectionEnabled:YES];

 

struct CGRect zrect;

float zres = 3.0f;

zrect = CGRectMake(0.0f, 0.0f, 320.0f * zres, 480.0f * zres);

 

[scroller setContentSize:zrect.size];

 

img = [[UIImage imageAtPath:path] retain];

[imgView initWithImage:img];

[imgView setEnabledGestures:YES];

[imgView setGestureDelegate: self];

 

int i;

 

for (i = 0; i < 0×2f; i++)

{

[imgView setEnabledGestures: i];

}

 

[scroller addSubview:imgView];

 

 

下面是如何获取缩放后的图片尺寸的代码:

 

 

- (void)didFinishGesture:(int)fp8 inView:(id)fp12 forEvent:(struct __GSEvent *)fp16

{

struct CGSize imgSize = [fp12 size];

[scroller setContentSize:CGSizeMake(imgSize.width * 2.0f, imgSize.height * 2.0f)];

原创粉丝点击