如何在uiscrollview中捏缩放图像

时间:2012-08-10 10:35:10

标签: iphone ios uitableview uiscrollview

我有tableview - >自定义单元格 - > uiscrollview - >的UIImageView

如何捏合和缩放uiscrollview ..

- (void)scrollViewDidZoom:(UIScrollView *)aScrollView
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
   methods are not working for me.

我的代码是:

    - (void)viewDidLoad
    {
        objCellfullscreen.scroll.maximumZoomScale = 6.0f;
        objCellfullscreen.scroll.minimumZoomScale= 0.5f;
        objCellfullscreen.scroll.scrollEnabled = YES;
        objCellfullscreen.scroll.contentSize = CGSizeMake(320, 460);
        objCellfullscreen.scroll.delegate =self;

    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *CellIdentifier = @"Cell";



        objCellfullscreen =(cellFullScreen *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

            if (objCellfullscreen==nil) {
              .......
              ...........
              .........
      }
      return  objCellfullscreen;
    }
- (void)scrollViewDidZoom:(UIScrollView *)aScrollView
{

    CGFloat offsetX = (objCellfullscreen.scroll.bounds.size.width > objCellfullscreen.scroll.contentSize.width)?(objCellfullscreen.scroll.bounds.size.width - objCellfullscreen.scroll.contentSize.width) * 0.5 : 0.0;
    CGFloat offsetY = (objCellfullscreen.scroll.bounds.size.height > objCellfullscreen.scroll.contentSize.height)?(objCellfullscreen.scroll.bounds.size.height - objCellfullscreen.scroll.contentSize.height) * 0.5 : 0.0;
    objCellfullscreen.img.center = CGPointMake(objCellfullscreen.scroll.contentSize.width * 0.5 + offsetX,objCellfullscreen.scroll.contentSize.height * 0.5 + offsetY);

}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return objCellfullscreen.img;
}

谢谢..请帮助。

1 个答案:

答案 0 :(得分:0)

你不应该在tableview中有一个滚动视图,因为UITableView继承自UIScrollView,这可能是为什么滚动视图的某些委托方法不会偶尔被调用/调用的原因。