I have added some UIButton in scrollveiw and linked it up with page control but when I tap my button so my pages control automatically scroll to page 1 which is initial page. So how can I erradicate this problem.
After TouchUp inside event it comes in this delegate function - (void) scrollViewDidScroll: (UIScrollView *) aScrollView
and move it to 1st index. Function implemented above.
- (void)viewDidLoad {
[super viewDidLoad];
scrollView = [[[UIScrollView alloc] initWithFrame:CGRectMake(32, 110, 261.0, 290.0)] autorelease];
scrollView.contentSize = CGSizeMake(NPAGES * 320.0f, scrollView.frame.size.height);
scrollView.pagingEnabled = YES;
scrollView.delegate = self;
self.scrollView.showsHorizontalScrollIndicator = NO;
for (int i=0; i< 10; i++) {
UIButton *mybtn = [UIButton buttonWithType:UIButtonTypeCustom];
mybtn.frame = CGRectMake(i * 320.0f+15, 0.0f, 231.0f, BASEHEIGHT);
mybtn.backgroundColor = [UIColor clearColor];
mybtn.tag = i;
[IINbtn addTarget:self action:@selector(websites:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:mybtn];
[scrollView bringSubviewToFront:mybtn];
}
}
- (void) pageTurn: (UIPageControl *) aPageControl
{
int whichPage = aPageControl.currentPage;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
scrollView.contentOffset = CGPointMake(320.0f * whichPage, 0.0f);
[UIView commitAnimations];
}
- (void) scrollViewDidScroll: (UIScrollView *) aScrollView
{
//id sender;
// UIButton *btn = sender;
CGPoint offset = aScrollView.contentOffset;
pageControl.currentPage = offset.x / 320.0f;
}