【问题标题】:apply zoom event with array of images of image view in UIScrllView在 ScrollView 中应用带有 imageview 图像数组的缩放事件
【发布时间】:2011-07-06 05:59:51
【问题描述】:
- (void)viewDidLoad 
{

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;


scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];

int numberOfImages = 32;
CGFloat currentX = 0.0f;

for (int i=1; i <= numberOfImages; i++) {

    // create image
    NSString *imageName = [NSString stringWithFormat:@"page-%d.jpg", i];
    UIImage *image = [UIImage imageNamed:imageName];
    imageView = [[UIImageView alloc] initWithImage:image];

    // put image on correct position
    CGRect rect = imageView.frame;
    rect.origin.x = currentX;
    imageView.frame = rect;

    // update currentX
    currentX +=454; //mageView.frame.size.width;

    [scrollView addSubview:imageView];
    [imageView release];
}
[scrollView addGestureRecognizer:tapGesture];

scrollView.contentSize = CGSizeMake(currentX, 800);
scrollView.pagingEnabled=YES;
scrollView.userInteractionEnabled = YES;
scrollView.maximumZoomScale = 15;
scrollView.minimumZoomScale = 0.5;
scrollView.bounces = NO;
scrollView.bouncesZoom = NO;
scrollView.delegate = self;

scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:scrollView];
[scrollView release];
[super viewDidLoad];

}
}

在上面的代码中,当我对单个图像应用缩放或点击事件时,它适用于此。但是,当相同的事件适用于图像数组时,则无法正常工作。为什么会这样?

【问题讨论】:

  • 在上面的代码中,我没有为缩放功能编写代码。因为我尝试过但它不起作用。所以你告诉我写什么代码和在哪里。

标签: iphone ipad uiscrollview xcode4 ipod-touch


【解决方案1】:

在这种图像流中实现缩放非常复杂。无论如何,我会建议你一个想法,

将手势添加到每个 imageView。在该方法中,添加一个新的滚动视图,带有各自的imageView..然后实现缩放。

编辑:

在tapgesture方法中,

1.找出此时可见的imageView。

2.然后用那个单一的图像视图创建一个新的滚动视图。

3.在新的滚动视图中实现缩放功能。

4.缩小时,如果新的scrollview大小等于实际值,则从super view中移除新的scrollview,使图像数组可见。

【讨论】:

  • 我添加了带有滚动视图的手势,可以添加到图像视图中。
  • 当我点击任何图像然后在控制台中显示点的坐标时,现在在 persent win iphone 模拟器上。所以现在我在那个事件中编写代码以便缩放图像?
【解决方案2】:

最简单的方法是先创建a big wrapper view,然后将其插入到ScrollView中。
然后将所有的 imageViews 添加到wrapper view

【讨论】:

  • 我如何创建包装视图?我对此一无所知。你能简单地说一下我吗?
猜你喜欢
  • 2012-07-11
  • 1970-01-01
  • 2012-12-19
  • 2020-06-18
  • 1970-01-01
  • 2018-07-19
  • 1970-01-01
  • 1970-01-01
  • 2021-03-25
相关资源
最近更新 更多