Cocoa touch UIScrollView仅在未命中子视图的情况下工作
我有一个不能向右滚动的滚动视图,我简化了下面的代码。 它绘制视图和一些水平按钮,我在实际代码中添加了更多内容。 如果拖动按钮之间的空白,视图将滚动。如果你碰巧把手指放在按钮上,它就不会滚动。 在一个相关的建议之后,我尝试添加delaysContentTouches=YES行,但似乎没有什么不同。 我做错了什么? 蒂亚, 抢劫 更新了代码Cocoa touch UIScrollView仅在未命中子视图的情况下工作,cocoa-touch,uiscrollview,uibutton,drag,Cocoa Touch,Uiscrollview,Uibutton,Drag,我有一个不能向右滚动的滚动视图,我简化了下面的代码。 它绘制视图和一些水平按钮,我在实际代码中添加了更多内容。 如果拖动按钮之间的空白,视图将滚动。如果你碰巧把手指放在按钮上,它就不会滚动。 在一个相关的建议之后,我尝试添加delaysContentTouches=YES行,但似乎没有什么不同。 我做错了什么? 蒂亚, 抢劫 更新了代码 - (void)viewDidLoad { l = [self landscapeView]; [self.view addSubview:l
- (void)viewDidLoad {
l = [self landscapeView];
[self.view addSubview:l];
[l release];
}
- (UIScrollView *) landscapeView {
// LANDSCAPE VIEW
UIScrollView *landscapeView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 325)];
landscapeView.backgroundColor = [UIColor whiteColor];
landscapeView.delaysContentTouches = YES;
NSInteger iMargin, runningY, n;
iMargin = 3;
runningY = iMargin;
for (n = 1; n <= 38; n++) {
//add day labels
UIButton *templabel = [[UIButton alloc] initWithFrame:CGRectMake(iMargin,runningY,320 - ( 2 * iMargin),20)];
templabel.backgroundColor = [UIColor grayColor];
[landscapeView addSubview:templabel];
[templabel release];
runningY = runningY + 30;
}
landscapeView.contentSize = CGSizeMake( 320, runningY);
return landscapeView;
}
我不能复制你的结果;当我创建滚动视图并添加按钮时,滚动仍然处于活动状态,即使在按下按钮时也是如此。您是否正在设置任何其他UIScrollView属性,或对任何方法进行子类化,而这些属性或子类化没有显示在简化代码中?看起来有一件事正在发生,那就是landScapeView的getter是一个复杂的构造函数……所以每次您执行[self-landScapeView]或self.landScapeView时,您正在创建一个全新的UIScrollView并对其进行操作 我会在您的.h文件中尝试以下内容:
@interface MyClass: MyParent {
UIScrollView *landscapeView;
}
@property (retain) UIScrollView *landscapeView;
…在.m文件中:
@implementation MyClass
@synthesize landscapeView;
(void)viewDidLoad
{ l = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 325)] autorelease];
[self.view addSubview:self.landscapeView]; [l release];
landscapeView.backgroundColor = [UIColor whiteColor];
landscapeView.delaysContentTouches = YES;
NSInteger iMargin, runningY, n;
iMargin = 3;
runningY = iMargin;
for (n = 1; n <= 38; n++) { //add day labels
UIButton *templabel = [[UIButton alloc] initWithFrame:CGRectMake(iMargin,runningY,320 - ( 2 * iMargin),20)];
templabel.backgroundColor = [UIColor grayColor];
[landscapeView addSubview:templabel];
[templabel release]; runningY = runningY + 30;
}
landscapeView.contentSize = CGSizeMake( 320, runningY);
}谢谢,格雷格,我试试看。我同意这是一个结构很差的旧代码。你认为这会解决滚动问题吗?RobOk,做了改变。仍然存在按钮无法单击的问题。我应该试着制作一个关于这个问题的迷你应用程序并上传它吗?我不知所措。