gpt4 book ai didi

iphone - 自动滚动scrollview

转载 作者:可可西里 更新时间:2023-11-01 17:09:45 26 4
gpt4 key购买 nike

我有一个问题。我想在 UIScrollView 中向用户显示一些内容。我想从下到上快速自动滚动 UIScrollView(就像在苹果商店 iPad 中一样)。我尝试使用 DDAutoscrollview(如果有人知道),但它对我不起作用。有人为我提供了autoscroll UIScrollView 的解决方案吗?任何代码片段都很好。

.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 赠送的遮阳篷竖起大拇指!!!


最佳答案

只需使用setContentOffset:animated:

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

编辑:

要像使用某种启动动画一样使用它,您可以在 scrollView 的 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:

要使滚动变慢,请使用:

- (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);
}];
}

关于iphone - 自动滚动scrollview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13258938/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com