-1

我也为 Scrollview(8images) + Toolbar 完成了代码。当我尝试单击工具栏按钮项时,滚动视图未按预期返回。下面是代码。

当我单击工具栏按钮时,没有触发“IBAction clickprjinfo”的操作,我已通过连接检查器中的 Barbuttonitem 确认对此 IBACTION 完成了“SentAction”。

在运行时,当我单击按住工具栏按钮 + 触摸 scoolview 屏幕 + 然后释放按钮时,它会触发 IBACTION。

任何人都可以帮助通知我的错误或更好的方式来理解这一点。

-(void)viewDidLoad
{
   [super viewDidLoad];
   [self pgcontrolview];
}

-(void) pgcontrolview  {
   pageC.numberOfPages=8;
   pageC.currentPage=0;
   for (int i=1; i<=8; i++)
   {
       UIImageView *images=[[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]]];
       images.frame=CGRectMake((i-1)*1024, 0, 1024, 760);
       [scroller addSubview:images];
   }
   scroller.delegate=self;
   scroller.contentSize=CGSizeMake(1024*8, 760);
   scroller.pagingEnabled=YES;

   UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handle_Tap:)];
   tap.numberOfTapsRequired = 1;
   tap.numberOfTouchesRequired = 1;
   [self.view addGestureRecognizer:tap];
}

-(IBAction)clickprjinfo:(id)sender{
   pageC.currentPage=1;
   CGRect frame=scroller.frame;
   frame.origin.x=0;//frame.size.width*page;
   frame.origin.y=0;
   [scroller scrollRectToVisible:frame animated:YES];
}
4

1 回答 1

5

添加手势委托方法如下

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// test if our control subview is on-screen
if ([touch.view isKindOfClass:[UIControl class]]) {
    // we touched a button, slider, or other UIControl
    return NO; // ignore the touch
}
return YES; // handle the touch
}

因为它考虑 UIButton 点击​​作为 UITapGesture,所以你不需要允许 UIButton 上的 UITapGesture,因为上面的委托方法忽略 UIControl 上的触摸(反过来 UIButton)允许执行

-(IBAction)clickprjinfo:(id)sender行动

于 2013-09-18T07:56:54.720 回答