UIScrollerView滚动与UIButton操作

时间:2015-08-03 11:33:23

标签: ios objective-c xcode uiscrollview uigesturerecognizer

我创建了一个具有四个页面效果的UIScrollerView,它们通过UIScrollView委托方法scrollViewDidScroll进行了更改和识别和更改。

我有一个前后UIButton,我想自动初始化卷轴,以便页面前进和后退。我的代码到目前为止

-(void)createScroller
{
    self.scroller = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, self.scrollContainerView.frame.size.height)];
    self.scroller.backgroundColor = [UIColor clearColor];
    self.scroller.pagingEnabled = YES;
    self.scroller.contentSize = CGSizeMake(pageCount * self.scroller.bounds.size.width, 0);
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    static NSInteger previousPage = 0;
    CGFloat pageWidth = scrollView.frame.size.width;
    float fractionalPage = scrollView.contentOffset.x / pageWidth;
    NSInteger page = lround(fractionalPage);

    if (previousPage != page) {


        NSLog(@"scrollViewPage : %ld", (long)page);

        if (page == 0) {
            [self.learnMoreButton setTitle:@"Learn more" forState:UIControlStateNormal];
        }

        if (page == 1) {
            [self.learnMoreButton setTitle:@"1 of 4" forState:UIControlStateNormal];
        }

        if (page == 2) {
            [self.learnMoreButton setTitle:@"2 of 4" forState:UIControlStateNormal];

        }

        if (page == 3) {
            [self.learnMoreButton setTitle:@"3 of 4" forState:UIControlStateNormal];
        }

        if (page == 4) {
            [self.learnMoreButton setTitle:@"4 of 4" forState:UIControlStateNormal];
        }

        previousPage = page;
    }
}

我假设我需要为UIScrollView设置动画来更改页面,但我不确定,还有什么行

    - (IBAction)pageForwardButtonPressed:(id)sender
 [UIView animateWithDuration:3 animations:^(void) {

//   animate page change of UIScrollView

    } completion:^(BOOL finished) {

//update page number

0 个答案:

没有答案