I have done code for Scrollview(8images) + Toolbar as well. When I try to click the toolbar button item the scrollview is not turned back as expected. below is the code.
When I click Toolbar button, no action triggered to "IBAction clickprjinfo", I have confirm done "SentAction" to this IBACTION via Barbuttonitem in connection inspector.
during runtime, when i click hold toolbar button + touch on scroolview screen + then release button, then it trigger the IBACTION.
Anyone help to notify my mistake or better way to understand this.
-(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];
}
Add Gesture delegate methods as below
- (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
}
Because it considering UIButton tapping as UITapGesture, so you don't need to allow UITapGesture on UIButton as the above delegate method ignore touch on UIControl (which in-turn UIButton) as allow to perform
-(IBAction)clickprjinfo:(id)sender
action