UICollectionView实现书本翻页布局

效果图:


UICollectionView能够实现你想要的任何布局,Vincent Ngo在raywenderlich中,用swift介绍了如何实现书本翻页布局,不得不佩服Vincent Ngo的想法,链接地址:http://www.raywenderlich.com/94565/how-to-create-an-ios-book-open-animation-part-1;

本文参考了这种思想,用OC编程实现了其中一部分效果,如上图所示;下面代码在每处都加上了详细解释,欢迎大家提供意见,

新建一个BookCell,继承自UIcollectionViewCell,在实现部分,重写applyLayoutAttributes方法,实现书本边缘圆角效果:

#import "BookCell.h"

@implementation BookCell

{
    BOOL isRightPage;
}

//初始化
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        //设置背景
        self.bgView = [[UIView alloc] initWithFrame:self.contentView.bounds];
        self.bgView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.bgView];
        
        //添加图片
        self.imageView = [[UIImageView alloc] initWithFrame:self.bgView.bounds];
        [self.bgView addSubview:self.imageView];
        
        //添加星座label
        self.textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 40)];
        self.textLabel.center = CGPointMake(self.bgView.bounds.size.width / 2 + 20, self.bgView.bounds.size.height - 20);
        [self.bgView addSubview:self.textLabel];
        
        //开启反锯齿
        self.layer.allowsEdgeAntialiasing = YES;
        
    }
    return self;
}

//默认自定义布局,布局圆角 和 中心线
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    //判断cell的
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值