IOS工具栏按钮项不会触发滚动条的操作

时间:2013-09-18 07:50:16

标签: ios uitoolbar uitoolbaritem

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

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

在运行期间,当我点击按住工具栏按钮+触摸scroolview屏幕+然后释放按钮,然后它会触发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];
}

1 个答案:

答案 0 :(得分:5)

添加Gesture委托方法如下

- (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行动