Iphone 捕获了在UiScrollView中触摸但无法在其他函数中访问的子视图。
我有UIScrollView,其中添加了子视图(图片)来执行此操作。每次用户触摸scrollview中的图片时,它都会在其顶部切换复选标记 NSMutableIndexSet*图片数组 1)不使用UIImageView,而是实现UIImageView的子级。然后试着倾听各个子视图上的触摸,这应该可以解决O(n)问题 2) 某些内容可能会自动发布,请仔细检查您的引用计数是否正确Iphone 捕获了在UiScrollView中触摸但无法在其他函数中访问的子视图。,iphone,uiscrollview,Iphone,Uiscrollview,我有UIScrollView,其中添加了子视图(图片)来执行此操作。每次用户触摸scrollview中的图片时,它都会在其顶部切换复选标记 NSMutableIndexSet*图片数组 1)不使用UIImageView,而是实现UIImageView的子级。然后试着倾听各个子视图上的触摸,这应该可以解决O(n)问题 2) 某些内容可能会自动发布,请仔细检查您的引用计数是否正确 尝试UIView*targetView=[self-hitTest:location with-event:nil] 感
UIView*targetView=[self-hitTest:location with-event:nil]代码>
感谢您的回复SLF!你能解释一下你所说的实现UiImageView的孩子是什么意思吗?对于自动释放问题,[(UIImageView*)[self-viewWithTag:i]image]基本上为空。那么带标签的self-viewwithTag:我是自动释放的吗?
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
if (!self.dragging) {
[self.nextResponder touchesEnded: touches withEvent:event];
NSLog(@"Touch down");
for (UITouch *touch in touches) {
for (int i = 1; i <= [self subviews].count; i++)
{
if(CGRectContainsPoint([[self viewWithTag:i]frame], [touch locationInView:self])){
NSLog(@"touched %d th view",i);
NSArray *subviews = [[self viewWithTag:i] subviews];
UIImageView *view = nil;
view = [subviews objectAtIndex:0];
if(view.hidden){
// add the index
[picturesArray addIndex:i];
view.hidden = NO; //check mark is shown
}else{
[picturesArray removeIndex:i];
view.hidden = YES; //check mark is not shown
}
// UIImageWriteToSavedPhotosAlbum([(UIImageView *)[self viewWithTag:i]image], nil, nil, nil); <- WORKS IF CALLED
}
}
}
}
NSLog(@"Element is %d",theIndexBuffer[i]);
UIImageWriteToSavedPhotosAlbum([(UIImageView *)[self viewWithTag:i]image], nil, nil, nil); <- THIS CRASHES