1、使用UITableView显示内容,应熟悉datasource 以及delegate设置以及方法的使用。
2、自定义cell写法,可以使用storyBoard以及xib来进行实现自定义的方法来实现相关的内容。
3、父子视图控制器之间的切换方法,有什么?pressent、model、push……
4、 动画core animation (在Quartz Core framework框架里面),UIView.h 文件中同样有动画的分类方法,且这里是用这个方法,可以查看代码。
5、:[self layoutIfNeeded];方法来实现页面的刷新,刷新页面的方法有好几个,不知道用到哪一个好,碰到再说吧,哪位大神知道他们的却别以及使用场景麻烦回复一下,3Q。
6、[self.view reloadData];tableView中重新加载书局的方法。
难点以及重点:就是cell的自定义、动画实现的方法。(这里并不是使用CALayer的类来进行实现的)
<span style="color:#FF0000;"><span style="font-size:14px;">ViewController 的类的方法:</span>
</span>#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITabBarControllerDelegate,UITableViewDataSource>
@end
#import "ViewController.h"
#import "CustomTableViewCell.h"
#import "SecondViewController.h"
@interface ViewController (){
NSIndexPath *_indexPath;
NSInteger _indexCount;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView2;
@property (strong, nonatomic) NSArray *contents;
@property (strong, nonatomic) SecondViewController *svc;
@property (copy, nonatomic) NSArray *imageName;
@end
@implementation ViewController
- (void)viewWillAppear:(BOOL)animated{
if (![_indexPath isEqual:nil] ) {
//重新加载数据
[self.tableView2 reloadData];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
_contents = @[@"lo90",@"dsgrt"];
_imageName = @[@"0.jpg",@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _contents.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
_indexPath = indexPath;
static NSString *_cellName = @"CustomTableViewCell";
CustomTableViewCell *_tableViewCell = [tableView dequeueReusableCellWithIdentifier:_cellName];
_tableViewCell.contentLabel.text = _contents[indexPath.row];
[_tableViewCell feedDataWithCustomCell];
return _tableViewCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
tableView.backgroundColor = [UIColor yellowColor];
return 200;
}
#pragma mark UItableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
_svc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self presentViewController:_svc animated:NO completion:nil];
}
@end
&&& ios中其实最为主要的是知道哪些方法是系统自动调用。
<pre name="code" class="objc">#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)onClickBack:(id)sender {
[self dismissViewControllerAnimated:NO completion:nil];
}
@end
#import "CustomTableViewCell.h"
@interface CustomTableViewCell (){
NSArray *_contents;
}
@end
@implementation CustomTableViewCell
//这里实现基本的数据显示
- (void)feedDataWithCustomCell{
_contents =@[@"循环显示内容1",@"循环显示内容2",@"循环显示内容3",@"循环显示内容4",@"循环显示内容5",@"循环显示内容6",@"循环显示内容7"];
self.label_ViewConstant.constant = CGRectGetHeight(self.SonOfCellView.frame);
[self layoutIfNeeded];
[self startAnimationWithIndex:0 withConstant:0];
}
//实现 动画的效果
- (void)startAnimationWithIndex:(NSInteger)index withConstant:(NSInteger)constant{
NSInteger nextConstant;
if (constant < 0) {
nextConstant = 0;
}else{
self.contentLabel.text = _contents[(index/2)%(_contents.count)];
nextConstant = -CGRectGetHeight(self.contentLabel.frame);
}
__weak typeof(self) weakSelf = self;
CGFloat duration = 1.0+arc4random()%100/100.0;
//实现动画效果,这里不是使用我们常用的基础动画或者关键动画。
[UIView animateWithDuration:duration+2 animations:^{
weakSelf.label_ViewConstant.constant = constant;
[weakSelf layoutIfNeeded];
} completion:^(BOOL finished) {
if (finished) {
if (constant<0) {
weakSelf.label_ViewConstant.constant = CGRectGetHeight(self.contentLabel.frame);
[weakSelf layoutIfNeeded];
}
[weakSelf startAnimationWithIndex:index+1 withConstant:nextConstant];
}
}];
}
@end
第二页面的控制器的类的代码:(只是实现了一个返回的界面
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)onClickBack:(id)sender {
[self dismissViewControllerAnimated:NO completion:nil];
}
@end
相关的StoryBoard的界面的属性设置以及注意事项:
右边对框内一定要选上,否则会出现有关的内容显示在页面上,没有达到预想的想过。
运行之后的效果是:
就是文字可以在里面自动的滑动,即使到了第二个页面之后,还是能够实现内容内容的刷新。哈哈。
重写的时候出现一个问题:
自定义的cell代码如下:
#import "CustomViewCell.h"
@interface CustomViewCell ()
@property (strong, nonatomic) NSArray *contents;
@end
@implementation CustomViewCell
- (void)feedTableViewCell{
_contents =@[@"循环显示内容1",@"循环显示内容2",@"循环显示内容3",@"循环显示内容4",@"循环显示内容5",@"循环显示内容6",@"循环显示内容7"];
self.toTopConstraint.constant = CGRectGetHeight(self.parentView.frame);
[self layoutIfNeeded];
[self startAnimationWithIndex:0 withConstant:20];
}
- (void) startAnimationWithIndex:(NSInteger)index withConstant:(NSInteger)constant{
NSInteger nextConstant;
if (constant !=20) {
nextConstant = 20;
}else{
//为什么是和这里的值有关的呢?
//出现问题:就是我们在运行第一次的时候显示的内容可能会变化,二第二次之后就不会发生变化,并且与这个值有很大的关系,如果设置为父视图的高度就没有问题,如果设置为其他的就会出现这个问题。
//原理:也就是没有设置为父视图的高度,在运行的时候,没有有相应的约束,这个时候会出现在运行的时候慢适应的过程。所以我们应该设置nextConstant的值为父视图的大小,或者设置label的宽度和高度的约束。
nextConstant = -20;
}
self.labelName.text = _contents[(index/2)%(_contents.count)];
[UIView animateWithDuration:3
animations:^{
self.toTopConstraint.constant = constant;
[self layoutIfNeeded];
} completion:^(BOOL finished) {
if (finished) {
if (constant != 20) {
self.toTopConstraint.constant = 60; [self layoutIfNeeded];
}
[self startAnimationWithIndex:index+1 withConstant:nextConstant];
}
}];
}
@end
运行的结果没有预想到的结果:
问题: 就是第一次的运行的label里面的值 出现往上运行的时候里面的值重新由大变小。
出现的问题设置的内容在代码有提示:(1)label没有对其高度和宽度进行设置约束 (2)设置的nextConstant的绝对值的大小不是父视图的大小的高度。
解决问题: (1)设置label的高、宽的约束 ,这样,上面的那个值就随便设置了 (2)nextConstant设置值为绝对值的大小(-),这样不够灵活。
小知识:
断点的方式:br set -r "didSelect(过滤字段)" 用来设置断点。