iPhone:带有多个 UIImageView 的 UIScrollview,具有放大/缩小效果

发布于 2024-12-21 23:09:35 字数 1468 浏览 1 评论 0原文

我的应用程序中有一个 UIscrollview,其中包含多个 UIimageview。我想应用捏放大/缩小功能。将 UIImageview 添加到 UIScrollView 的代码如下,

self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
    [scViewObject setCanCancelContentTouches:NO];
    scViewObject.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scViewObject.clipsToBounds = NO;        // default is NO, we want to restrict drawing within our scrollview
    scViewObject.scrollEnabled = YES;
    scViewObject.alwaysBounceHorizontal=YES;
    scViewObject.pagingEnabled = YES;

    UIView *view = nil;
    NSArray *subviews = [scViewObject subviews];
    for (view in subviews)
    {
        [view removeFromSuperview];
    }
    int left=20;
    numberOfViewController=[ListOfImages count];
    //NSMutableArray *controllers = [[NSMutableArray alloc] init];
    for (unsigned ii = 0; ii < numberOfViewController; ii++)
    {
        UIImageView *temp=[[UIImageView alloc] init];
        temp.contentMode=UIViewContentModeScaleAspectFit;
        temp.userInteractionEnabled = YES;
        temp.multipleTouchEnabled  = YES;
        temp.clipsToBounds = YES;
        temp.image=[ListOfImages objectAtIndex:ii];
        temp.frame=CGRectMake(left, 0, 280, 365);
        temp.tag=ii;

        [scViewObject addSubview:temp];
        left=left+320;
    }

    [scViewObject setContentSize:CGSizeMake((numberOfViewController * kScrollObjWidth), 365)];

scViewObject 是 UIscrollview。请建议我如何添加放大/缩小功能

I have a UIscrollview in my application which contains multiple UIimageview. I want to apply the pinch zoom in / out functionality.Code for adding UIImageview to UIScrollView is following

self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
    [scViewObject setCanCancelContentTouches:NO];
    scViewObject.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scViewObject.clipsToBounds = NO;        // default is NO, we want to restrict drawing within our scrollview
    scViewObject.scrollEnabled = YES;
    scViewObject.alwaysBounceHorizontal=YES;
    scViewObject.pagingEnabled = YES;

    UIView *view = nil;
    NSArray *subviews = [scViewObject subviews];
    for (view in subviews)
    {
        [view removeFromSuperview];
    }
    int left=20;
    numberOfViewController=[ListOfImages count];
    //NSMutableArray *controllers = [[NSMutableArray alloc] init];
    for (unsigned ii = 0; ii < numberOfViewController; ii++)
    {
        UIImageView *temp=[[UIImageView alloc] init];
        temp.contentMode=UIViewContentModeScaleAspectFit;
        temp.userInteractionEnabled = YES;
        temp.multipleTouchEnabled  = YES;
        temp.clipsToBounds = YES;
        temp.image=[ListOfImages objectAtIndex:ii];
        temp.frame=CGRectMake(left, 0, 280, 365);
        temp.tag=ii;

        [scViewObject addSubview:temp];
        left=left+320;
    }

    [scViewObject setContentSize:CGSizeMake((numberOfViewController * kScrollObjWidth), 365)];

here scViewObject is UIscrollview. Please suggest that how can i add zoom in / out functionality

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巷雨优美回忆 2024-12-28 23:09:35

您需要观看几个 ADC 视频:

WWDC 2010:使用滚动视图设计应用程序

WWDC 2011:高级滚动视图技术,

但基本上您需要在外部滚动视图的每个“页面”内实现缩放滚动视图并将每个图像添加到每个缩放滚动视图中。

另请参阅文档
和示例代码

There is a couple of ADC video that you'll want to watch:

WWDC 2010 : Designing Apps with Scroll views

WWDC 2011 : Advanced Scrollview Techniques

but basically you'll want to implement a zooming scrollview inside each "page" of the outer scroll view and add each image into each of these zooming scroll views.

Also see the documentation
And example code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文