4

我有个问题。我想向用户显示一些内容UIScrollView。我想从下到autoscrollUIScrollView快速(就像在苹果商店里一样iPad)。我尝试使用DDAutoscrollview(如果有人知道),但它对我不起作用。有人为我解决问题autoscrollUIScrollView?任何代码片段都会很好。

。H

@interface Interface1 : UIViewController {

    IBOutlet UIScrollView *scroller;
    IBOutlet UILabel *warnung;

}

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

.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];
}

谢谢。


> 为 TOBI 提供的 AWNSER 点赞!!!


4

1 回答 1

8

只需使用setContentOffset:animated:

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

编辑:

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

- (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:

要使滚动速度变慢,请使用以下命令:

- (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);
    }];
}
于 2012-11-06T20:41:39.660 回答