效果图:
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的