简体   繁体   English

如何在 iPhone 的 uiscrollview 内的 uiimageview 中实现捏合捏合?

[英]how to implement pinch in pinch out in uiimageview which is inside uiscrollview in iphone?

Hello I have implemented photoslide show using apple's scrolling example.Below is code:您好,我已经使用苹果的滚动示例实现了幻灯片放映。下面是代码:

- (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;

}

Now i want to implement zoom in zoom out.How can i do that?any sample code or example?现在我想实现放大缩小。我该怎么做?任何示例代码或示例?

create a uiscrollview within a uiscrollview with a uiimageview within that.在 uiscrollview 中创建一个 uiscrollview 并在其中创建一个 uiimageview。 the outer uiscrollview scrolls horizontally and the inner one is set up for pinch and zoom.外部 uiscrollview 水平滚动,内部 uiscrollview 设置为缩放。 IOS is actually smart enough to engage the parent uiscrollview when the inner scroller is totally zoomed out or is at the edge. IOS 实际上足够聪明,可以在内部滚动条完全缩小或位于边缘时接合父 uiscrollview。

Many examples are out there to create a pinch/zoom app uiscrollview.许多示例都可以创建捏/缩放应用程序 uiscrollview。

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];

to make a scrollview zoomable do not forget to implement the UIScrollViewDelegate使滚动视图可缩放不要忘记实现 UIScrollViewDelegate

and add:并添加:

-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll {
return contentView;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM