iOS中scrollview自动滚动的实现
来源:互联网 发布:华为网络交换机 编辑:程序博客网 时间:2024/05/22 13:29
iOS中scrollview自动滚动的实现
.h文件
[plain]
@interface Interface1 : UIViewController{
IBOutlet UIScrollView*scroller;
IBOutlet UILabel *warnung;
}
@property (nonatomic, retain) IBOutletUIScrollView*scrollView;
.m文件
[plain]
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGPoint bottomOffset =CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentSize.height- self.scrollView.bounds.size.height);
[self.scrollViewsetContentOffset:bottomOffset animated:NO];
CGPoint newOffset = self.scrollView.contentOffset;
newOffset.y = 0;
[self.scrollViewsetContentOffset:newOffset animated:YES];
}
- (void)viewDidLoad
{
[scrollersetScrollEnabled:YES];
[scrollersetContentSize:CGSizeMake(320, 420)];
[superviewDidLoad];
}
使用setContentOffset:animated:
[plain]
UIScrollView *scrollView = ...;
CGPoint newOffset = scrollView.contentOffset;
newOffset.y = 0;
[scrollViewsetContentOffset:newOffset animated:YES];
如果需要开场动画的效果,在scrollView的viewcontroller实现
[plain]
- (void)viewDidLoad
{
[super viewDidLoad];
// ...
CGPoint bottomOffset =CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentSize.height- self.scrollView.bounds.size.height);
[self.scrollViewsetContentOffset:bottomOffset animated:NO];
}
- (void)viewDidAppear:(BOOL)animated
{
[superviewDidAppear:animated];
CGPoint newOffset = self.scrollView.contentOffset;
newOffset.y = 0;
[self.scrollViewsetContentOffset:newOffset animated:YES];
}
移动的慢点,用timer实现:
[plain]
- (void)viewDidLoad
{
[super viewDidLoad];
// ...
CGPoint bottomOffset =CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentSize.height- self.scrollView.bounds.size.height);
[self.scrollViewsetContentOffset:bottomOffset animated:NO];
}
- (void)viewDidAppear:(BOOL)animated
{
[superviewDidAppear:animated];
CGPoint bottomOffset =CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentSize.height- self.scrollView.bounds.size.height);
//设置延迟时间
float scrollDurationInSeconds= 4.0;
//计算timer间隔
float totalScrollAmount =bottomOffset.y;
float timerInterval =scrollDurationInSeconds / totalScrollAmount;
[NSTimerscheduledTimerWithTimeInterval:timerInterval target:selfselector:@selector(scrollScrollView:) userInfo:nil repeats:YES];
}
- (void)scrollScrollView:(NSTimer *)timer
{
CGPointnewScrollViewContentOffset = self.scrollView.contentOffset;
//向上移动 1px
newScrollViewContentOffset.y-= 1;
newScrollViewContentOffset.y= MAX(0, newScrollViewContentOffset.y);
//如果到顶了,timer中止
if (newScrollViewContentOffset.y== 0) {
[timerinvalidate];
}
//最后设置scollView's contentOffset
self.scrollView.contentOffset= newScrollViewContentOffset;
}
- iOS中scrollview自动滚动的实现
- iOS中scrollview自动滚动的实现
- iOS中scrollview自动滚动的实现
- iOS中scrollview自动滚动的实现
- iOS ScrollView自动滚动的代码
- ScrollView自动滚动实现
- QML中ScrollView的自动滚动
- iOS scrollView循环自动滚动
- IOS实现自动循环滚动广告--ScrollView的优化和封装
- IOS实现自动循环滚动广告--ScrollView的优化和封装
- android 实现ScrollView自动滚动
- IOS系列——scrollview自动滚动
- iOS的ScrollView包含TableView使用AutoLayout实现滚动
- iOS UIScrollView中实现分页滚动--定时自动滚动分页
- 利用ScrollView实现布局自动滚动
- 利用ScrollView实现布局自动滚动
- Android 利用ScrollView实现布局自动滚动
- 利用ScrollView实现布局自动滚动
- WIndows App 开发环境搭建
- new 对象加括号和不加括号的区别
- Fragment中使用 startActivityForResult
- (3)flume 单节点写入HDFS练习 以及 自定义拦截器 进行formatLog
- 计蒜客004-简单斐波那契
- iOS中scrollview自动滚动的实现
- 为项目添加lib库
- Class.getResource() and ClassLoader.getResource()
- Navicat 解决方案之ORA-28547
- STM32模拟 IIC
- win8.1除了应用界面的应用,其他系统程序都不能上网,包括IE
- Spring MVC 教程,快速入门,深入分析
- 在TextView显示前测量字符串设置显示行数
- MySQL双机热备份实施方案