##UICollectionViewLayout写一个Layout继承自UICollectionViewLayout,实现以下方法://返回cell的Layout属性- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath;//返回SupplementaryView的Layout属性(HeaderView、FooterView)- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath;//返回DecorationView的Layout属性- (nullable UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString*)elementKind atIndexPath:(NSIndexPath *)indexPath;实现prepareLayout方法,完成布局。在prepareLayout方法中调用[super prepareLayout];-(void)prepareLayout{ [super prepareLayout]; [self.attrsArr removeAllObjects]; //注册Decoration class [self registerClass:[DecorationView class] forDecorationViewOfKind:@"DecorationView"];//注册Decoration View } layoutAttributesForElementsInRect方法中添加需要布局的所有Elements的Attributes -(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect{ NSInteger count=[self.collectionView numberOfItemsInSection:0]; //添加DecorationView的LayoutAttributes [self.attrsArr addObject:[self layoutAttributesForDecorationViewOfKind:@"DecorationView" atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]]; for (int i=0; i, <#CGFloat ty#>):只能变化一次,因为这种方式的变化始终是以最原始的状态值进行变化的,所以只能变化一次
UIButton *head = (UIButton *) [self.view viewWithTag:10];
head.transform = CGAffineTransformMakeTranslation(0,-10);
(2)CGAffineTransformTranslate(CGAffineTransform t, <#CGFloat tx#>, <#CGFloat ty#>):能够多次变化,每次变化都是以上一次的状态(CGAffineTransform t)进行的变化,所以可以多次变化
head.transform = CGAffineTransformTranslate(head.transform, 0, -10);
(3) CGAffineTransformIdentity:清空所有的设置的transform(一般和动画配合使用,只能使用于transfofrm设置的画面)
UIButton *head = (UIButton *) [self.view viewWithTag:10];
head.transform = CGAffineTransformIdentity;
(4)CGAffineTransformMakeScale( CGFloat sx, CGFloat sy) (缩放:设置缩放比例)仅通过设置缩放比例就可实现视图扑面而来和缩进频幕的效果。
UIButton *head = [self.view viewWithTag:10];
head.transform = CGAffineTransformScale(head.transform,1.5,1.5);
(5) CGAffineTransformMakeRotation( CGFloat angle) (旋转:设置旋转角度)
UIButton *head = [self.view viewWithTag:10];
head.transform = CGAffineTransformMakeRotation(M_PI_2);
###实现UIView绕固定点旋转
定义方法:
CGAffineTransform GetCGAffineTransformRotateAroundPoint(UIView *view,float centerX, float centerY ,float x ,float y ,float angle){
//centerX ,centerY 为当前View的中心点
x = x - centerX;
y = y - centerY;
CGAffineTransform trans = CGAffineTransformTranslate(view.transform,x, y);
trans = CGAffineTransformRotate(trans,angle);
trans = CGAffineTransformTranslate(trans,-x, -y);
return trans;
}
使用如下:
float centerSecondX = self.secondHand.bounds.size.width/2;
float centerSecondY = self.secondHand.bounds.size.height/2;
float xSecond = self.secondHand.bounds.size.width/2;
float ySecond = self.secondHand.bounds.size.height;
CGAffineTransform transSecond = GetCGAffineTransformRotateAroundPoint(self.secondHand,centerSecondX,centerSecondY ,xSecond,ySecond,1*second/30.0*M_PI);
self.secondHand.transform = transSecond;
效果:
网友评论