自动滚动scrollview [英] Automatic scrolling scrollview

查看:102
本文介绍了自动滚动scrollview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。我想在 UIScrollView 中显示用户的一些内容。我希望 autoscroll UIScrollView 从下到上快速(就像苹果商店 iPad )。我试图使用 DDAutoscrollview (如果有人知道),但它对我不起作用。有人给我一个解决方案 autoscroll a UIScrollView ?任何代码片段都不错。

I have a question. I want to display the user some content in a UIScrollView. I want to autoscroll the UIScrollView fast from bottom to top (like in the apple stores iPad). I tried to use DDAutoscrollview (If someone knows), but it doesn't work for me. Do have someone a solution for me to autoscroll a UIScrollView? Any code snippets would be nice.

@interface Interface1 : UIViewController {

    IBOutlet UIScrollView *scroller;
    IBOutlet UILabel *warnung;

}

@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;



.m



.m

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    CGPoint bottomOffset = CGPointMake(self.scrollView.contentOffset.x, 
                                       self.scrollView.contentSize.height - 
                                         self.scrollView.bounds.size.height);
    [self.scrollView setContentOffset:bottomOffset animated:NO];

    CGPoint newOffset = self.scrollView.contentOffset;
    newOffset.y = 0;
    [self.scrollView setContentOffset:newOffset animated:YES];
}

- (void)viewDidLoad {        
    [scroller setScrollEnabled:YES];
    [scroller setContentSize:CGSizeMake(320, 420)];    
    [super viewDidLoad];
}

谢谢。

推荐答案

只需使用 setContentOffset:animated:

UIScrollView *scrollView = ...;
CGPoint newOffset = scrollView.contentOffset;
newOffset.y = 0;
[scrollView setContentOffset:newOffset animated:YES];

修改:

要像使用某种开始动画一样使用它,你可以在scrollView的视图控制器中执行此操作:

To use it like some kind of start animation you could do this in the scrollView's view controller:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // ...

    CGPoint bottomOffset = CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
    [self.scrollView setContentOffset:bottomOffset animated:NO];
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    CGPoint newOffset = self.scrollView.contentOffset;
    newOffset.y = 0;
    [self.scrollView setContentOffset:newOffset animated:YES];
}

编辑2/3:

要使滚动速度变慢,请使用:

To make the scrolling happen slower, use this:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // ...

    CGPoint bottomOffset = CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
    [self.scrollView setContentOffset:bottomOffset animated:NO];
}


- (void)viewDidAppear:(BOOL)animated
{    
    [super viewDidAppear:animated];

    float scrollDuration = 4.0;

    [UIView animateWithDuration:scrollDuration animations:^{
        self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, 0);
    }];
}

这篇关于自动滚动scrollview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆