滚动视图按钮循环滚动到某个位置,然后返回到我当前所处的位置

时间:2016-04-04 21:30:19

标签: ios objective-c uiscrollview

我想点击一个按钮。滚动视图将滚动到某个y位置,当我再次单击它时,它将返回到我当前在滚动视图中所处的位置。我无法理解。

int position1 = 0;

- (IBAction)scrollToPosition1:(id)sender {
    int scrollYsaved;

    position1++;
    switch (position1) {
        case 1:
            scrollYsaved = scrollAll.contentOffset.y;

            [scrollAll scrollRectToVisible:CGRectMake(10, 4190, scrollAll.frame.size.width, scrollAll.frame.size.height) animated:YES];

            break;
        case 2:
            [scrollAll scrollRectToVisible:CGRectMake(10, scrollYsaved, scrollAll.frame.size.width, scrollAll.frame.size.height) animated:YES];

            if (position1=2)
            {
                position1=0;
            }

            break;
    }

0 个答案:

没有答案