首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在iphone的uiscrollview中实现uiimageview中的pinch in pinch out?

如何在iphone的uiscrollview中实现uiimageview中的pinch in pinch out?
EN

Stack Overflow用户
提问于 2011-05-03 14:52:19
回答 1查看 4.9K关注 0票数 1

你好,我已经实现了使用苹果的滚动example.Below是代码的照片幻灯片显示:

代码语言:javascript
复制
- (void)viewDidLoad {

    appDelegate=[(FoodAppDelegate *)[UIApplicationsharedApplication]delegate];
    kNumImages=[parray count];
    self.view.backgroundColor=[UIColor viewFlipsideBackgroundColor];
    [scrollView1 setBackgroundColor:[UIColor blackColor]];
    [scrollView1 setCanCancelContentTouches:NO];
    scrollView1.indicatorStyle=UIScrollViewIndicatorStyleWhite;
    scrollView1.clipsToBounds=YES;
    scrollView1.scrollEnabled=YES;   
        scrollView1.pagingEnabled=YES;
    scrollView1.minimumZoomScale=0.5;
    scrollView1.delegate=self;
    scrollView1.maximumZoomScale=6.0;
    scrollView1.bouncesZoom=YES;
    NSLog(@"view did load called");
    NSUInteger i;
    for(i=0;i<kNumImages;i++)
    {
        NSLog(@"for loop of view did load called");
        NSURL *url=[NSURL URLWithString:[parray objectAtIndex:i]];
        NSLog(@"url object at index %i is %@",i,url);
        UIImage *image=[UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
        imageView=[[UIImageView alloc] initWithImage:image];
        CGRect rect=imageView.frame;
        rect.size.height=kScrollObjHeight;
        rect.size.width=kScrollObjWidth;
        imageView.frame=rect;
        imageView.tag=i+1;
        [scrollView1 addSubview:imageView];

    }
    [scrollView1 setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
    [self layoutScrollImages];
    [super viewDidLoad];
}



-(void)layoutScrollImages
{
    int c=appDelegate.selectedphoto-1;
    kNumImages=[parray count];
    view=nil;
    NSArray *subviews=[scrollView1 subviews];
    CGFloat curXLoc=0;
    for(view in subviews)
    {
        if([view isKindOfClass:[UIImageView class]] && view.tag>0)
        {
            CGRect frame=view.frame;
            frame.origin=CGPointMake(curXLoc, 0);
            view.frame=frame;
            curXLoc+=(kScrollObjWidth);
        }}
    [scrollView1 setContentSize:CGSizeMake((kNumImages *kScrollObjWidth),200)];
    CGPoint lastFrame = CGPointMake(( c* kScrollObjWidth), 0.0f);
    [scrollView1 setContentOffset:lastFrame];
    scrollView1.showsHorizontalScrollIndicator=NO;
    scrollView1.showsVerticalScrollIndicator=NO;

}

现在我想在缩放out.How中实现缩放,我能做到吗?有没有示例代码?

EN

回答 1

Stack Overflow用户

发布于 2011-11-04 03:30:32

在uiscrollview中创建一个uiscrollview,其中包含一个uiimageview。外部的uiscrollview水平滚动,内部的设置为收缩和缩放。IOS实际上足够智能,可以在内部滚动条完全缩小或处于边缘时与父uiscrollview接触。

有很多例子可以创建一个收缩/缩放应用程序uiscrollview。

代码语言:javascript
复制
scrollView=[[UIScrollView alloc] initWithFrame:[BFCoords sharedBFCoords].APP_RECT];
scrollView.scrollEnabled=YES;
scrollView.maximumZoomScale=1;
scrollView.minimumZoomScale=.5;
scrollView.delegate=self;
scrollView.clipsToBounds=YES;



contentView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, [BFCoords sharedBFCoords].APP_WIDTH*2, [BFCoords sharedBFCoords].APP_HEIGHT*2)];
scrollView.contentSize=CGSizeMake([BFCoords sharedBFCoords].APP_WIDTH*2, [BFCoords sharedBFCoords].APP_HEIGHT*2);

[scrollView addSubview:contentView];

[self addSubview:scrollView];

scrollView.zoomScale=.5;
[scrollView setBackgroundColor:[UIColor blueColor]];
self.hidden=NO;
self.alpha=1;

[contentView release];
[scrollView release];

要使滚动视图可缩放,请不要忘记实现UIScrollViewDelegate

并添加:

代码语言:javascript
复制
-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll {
return contentView;}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5866086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档