下载了一个自动滚动的源码,学习一下,有点类似qq音乐里的歌词,不同的是歌词滚动是按照时间轴的,需要定位。
下载源码,有两个文件夹,一个是自己设计的类。
这是三个自定义的类,分别继承UIScrollView,UITableView,UITextView的类。
里面代码一样,为了使用不同控件时调用。
再看AppDelegate.m
选定一个打开加载的nib文件
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
再看二级视图文件TextViewController.h里引入头文件后定义一个textView输出口
@property (nonatomic, strong) IBOutlet DAAutoTextView *textView;
在TextViewController.m里给委托后直接开始滚动。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"Text View";
textView.delegate = self;
[textView startScrolling];
}
后面是两个停止手拖动后的操作,有细微的不同
首先
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate)
{
[textView startScrolling];
}
}
是手指滚动scrollView,手释放页面时页面已经停止时调用。
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[textView startScrolling];
}
是手指滚动scrollView,手释放时依旧滚动时调用。。