iOS UIScrollView无需用户交互和程序化滚动

时间:2011-09-01 19:55:03

标签: ios uiscrollview scroll user-interaction

是否可以在没有用户滚动的情况下拥有UIScrollView,因此可以以编程方式滚动UIScrollView吗?

2 个答案:

答案 0 :(得分:2)

是的,您可以使用这些方法以编程方式滚动:

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated

您也可以设置userInteractionEnabled=NO以禁用用户触摸事件。

答案 1 :(得分:0)

试试这个:

-(void)scrollViewProgramatically
{
        UIScrollView *scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(x, y, 250, 150)];
        scrollview.showsVerticalScrollIndicator=YES;
        scrollview.scrollEnabled=YES;
        scrollview.userInteractionEnabled=YES;
        scrollview.backgroundColor = [UIColor whiteColor];
        scrollview.contentSize = CGSizeMake(1250,250);
        [scrollview addSubview:scrollview];
}