Bic*_*ops 3 objective-c uiscrollview ios
我已经覆盖了子类,它拒绝调用touchesShouldCancelInContentView.我发誓我以前写过代码来做这件事.我正在覆盖该类,以便某些视图不会将触摸事件传递给滚动视图.
随着课程
@interface SlidingWindowScrollView : UIScrollView
{
UIView* noTouchView;
}
@property (nonatomic, retain) UIView* noTouchView;
@end
Run Code Online (Sandbox Code Playgroud)
并实施
@implementation SlidingWindowScrollView
@synthesize noTouchView;
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
BOOL shouldCancel = NO;
if(view == noTouchView)
shouldCancel = YES;
NSLog(@"shouldCancel %d", shouldCancel);
return shouldCancel;
}
@end
Run Code Online (Sandbox Code Playgroud)
在xib中,我在其中抛出一个scrollview和一个uiview,并在VC视图中写入这个加载.
scrollView.contentSize = CGSizeMake(scrollView.bounds.size.width*2,
scrollView.bounds.size.height);
scrollView.pagingEnabled = YES;
scrollView.canCancelContentTouches = YES;
contentView.frame = CGRectMake(scrollView.frame.size.width + 20,
0,
scrollView.frame.size.width,
scrollView.frame.size.height);
contentView.userInteractionEnabled = YES;
scrollView.noTouchView = contentView;
[scrollView setContentOffset:CGPointMake(scrollView.bounds.size.width, 0) animated:YES];
Run Code Online (Sandbox Code Playgroud)
我不知道是什么给了.这应该是一个简单的覆盖.我确保自定义类在XIB中是正确的,并且出口都说它是我的UIScrollView的新子类.我不是故意放肆但在最新的iOS API中做了些什么?这似乎应该很容易但它从不调用函数touchesShouldCancelInContentView.我很困惑.我非常感谢有人可以证明我错了并且让这个函数被scrollView调用.我想应该注意的是,print语句确实打印了,但可以一致地完成
如果你能在你的机器上工作,请告诉我,因为我没有看到任何错误.这让我疯了@ _ @希望有人可以帮助我.谢谢.
dav*_*den 13
从我所看到的,你没有得到touchesShouldCancelInContentView:或touchesShouldBegin:withEvent:inContentView:callbacks,除非你将delayedContentTouches设置为NO:
scrollView.delaysContentTouches = NO;
Run Code Online (Sandbox Code Playgroud)
小智 5
我被困在这个问题上一段时间,以防你读过这个,你需要在触摸touchesShouldCancelInContentView触发之前设置以下两个属性
scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = YES;
Run Code Online (Sandbox Code Playgroud)
只是scrollView.delaysContentTouches = NO不会开火,如果scrollView.canCancelContentTouches = NO
| 归档时间: |
|
| 查看次数: |
6457 次 |
| 最近记录: |