我试过这个事件我需要滚动事件,还需要按钮点击事件。这里我使用了多个uiview,并且我放置了按钮(需要动作滚动和按钮动作)任何人都可以提供解决方案吗?
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if ([self pointInside:point withEvent:event]) {
return _scrollView;
}
return nil;
}
在上面的代码滚动动作发生但按钮动作没有发生。
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if ([self pointInside:point withEvent:event]) {
return nil;
}
return nil;
}
在上面的代码按钮操作正在发生,但滚动只发生在其视图中,无法滚动其他滚动视图。
答案 0 :(得分:1)
简单的解决方案是在scrollview中添加一个scrollview apply paging,并在scrollview中添加你的Uiview,假设您必须显示5个视图然后尝试关注。
yourScroll = [[UIScrollView alloc]init];
yourScroll.frame = CGRectMake(45, 45, 230, 300);
yourScroll.backgroundColor = [UIColor clearColor];
yourScroll.contentSize = CGSizeMake(yourScroll.frame.size.width * 5, yourScroll.frame.size.height);
[yourScroll setPagingEnabled : YES];
[yourScroll setDelegate:self];
int incX = 0 ;
for( int i = 0; i < 2; i++)
{
UIView *myView = [[UIView alloc]initWithFrame:CGRectMake (incX,0,yourScroll.frame.size.width,yourScroll.frame.size.height)];
//Create a button and give it the tag like
button.tag = i;
//Now add a selector to the button and add the button to your view;
[myView addSubview:button]
[yourScroll addSubview:myView];
incX+= 230;
}
现在这是您点击按钮的滚动选择器:
- (IBAction)changePage:(id)sender
{
int page = [sender tag];
NSLog(@"the page is = %i",page);
CGRect frame = yourScroll.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[yourScroll scrollRectToVisible:frame animated:YES];
}