编程技巧 - 10

1.旋转最好用Core Animation !

- (void)startAnimation
{
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 1.f;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = MAXFLOAT;
    [_inImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}



2.怎么制作优雅的tableview  loading效果:

可以在tableviewFooterView里面设置这个效果,因为显示出FooterView的时候肯定在刷新数据表之前

等刷新完Cell再将它替换掉,参考:仿开眼APP:https://github.com/iosfighterlb/OpenEyesDemo

HyTableViewFooterView:

@implementation HyTableViewFooterView

+ (instancetype) loadView
{
    NSArray * ar = [[NSBundle mainBundle] loadNibNamed:@"HyTableViewFooterView" owner:self options:nil];
    HyTableViewFooterView *footerView = [ar lastObject];
    [footerView startAnimation];
    footerView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 68);
    return [ar lastObject];
}

- (void)startAnimation
{
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 1.f;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = MAXFLOAT;
    [_inImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

@end

在ViewDidLoad中展示刷新界面:

    _tableView.tableFooterView = [HyTableViewFooterView loadView];

viewForFooterInSection方法中刷新,将它替换或者移除(因为刷新完数据,这个方法会稍后才调用):

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    id obj = [_footerViews objectAtIndex:section];
    
    if (section < _footerViews.count) {
        if ([obj isKindOfClass:[UIView class]]) {
            return obj;
        }
    }
    HyTableViewCellFooterView *footerView = [HyTableViewCellFooterView loadView];
    footerView.h = _tableView.rowHeight;
    BaseClass *clas = [_dataSource objectAtIndex:section];
    SectionList *list = [clas.sectionList lastObject];
    footerView.data = [list.itemList firstObject];
    [_footerViews insertObject:footerView atIndex:section];
    return footerView;
}




3.自定义Cell的尺寸可以这样来设置:

@implementation VideoListTableViewCell

// 在这个方法中添加所有的子控件
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        UIImageView *image = [[UIImageView alloc] init];
        [self.contentView addSubview:image];
        self.ImageView = image;
        
        UIImageView *shadeView = [[UIImageView alloc]init];
        shadeView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
        self.shadeView = shadeView;
        [image addSubview:self.shadeView];
        
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.font = [UIFont fontWithName:MyChinFont size:15.f];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        UILabel *messageLabel = [[UILabel alloc] init];
        messageLabel.textColor = [UIColor whiteColor];
        messageLabel.font = [UIFont systemFontOfSize:12.f];
        messageLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:messageLabel];
        self.messageLabel = messageLabel;
    }
    return self;
}

// 设置所有的子控件的frame
- (void)layoutSubviews
{
    [super layoutSubviews];

    self.ImageView.frame = self.bounds;
    
    self.shadeView.frame = self.bounds;
    
    /** 标题 */
    self.titleLabel.frame = CGRectMake(5, self.bounds.size.height/2 - 20, self.bounds.size.width - 10, 30);
    
    /** 信息 */
    self.messageLabel.frame = CGRectMake(0, _titleLabel.bottom + 5, _titleLabel.width, 25);
}

@end

在layoutsubviews中设置,嘿嘿。




4.对于一些类不一样的方法,可以先设置属性,再进行强转

@property (nonatomic, strong) StoreViewController *storeViewController;

/
    _storeViewController = (StoreViewController *)controller;  //这里的controller是UIViewControoler类型
    _storeViewController.serverID = serverId;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值