uicollectionview下单独使用uibutton然后setimage或者直接使用uiimageview然后一定角度旋转后发现size会变动
解决方案:添加uibutton到uicollectionvview然后添加uiimageview到uibutton上而后旋转没有问题
但是点击时候即便设置的uiimageview的相关可点击属性依然无法实现button的点击,解决途径:tapgesture判断
代码如下:
self.subThemeGobackBtn = [UIButton
buttonWithType:UIButtonTypeCustom];
self.subThemeGobackBtn.frame = CGRectMake(self.collectionView.bounds.size.width
/ 2 + 60.0f, positionY, 0.0f, 0.0f);
[self.subThemeGobackBtn setBackgroundColor:[UIColor
clearColor]];
// [self.subThemeGobackBtn
addTarget:self action:@selector(gobackToPerviousScreen:)
forControlEvents:UIControlEventTouchUpInside];
[self.collectionView addSubview:self.subThemeGobackBtn];
self.buttonImageView = [[UIImageView
alloc]initWithImage:[UIImage
imageNamed:@"gobackicon.png"]];
self.buttonImageView.frame
= CGRectMake(0.0f, 0.0f, 100.0f, 20.0f);
self.buttonImageView.alpha = 0.0f;
self.buttonImageView.tag = 0;
self.buttonImageView.backgroundColor = [UIColor
blueColor];
self.buttonImageView.userInteractionEnabled =
YES;
[self.subThemeGobackBtn
addSubview:self.buttonImageView];
[UIView
animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState
animations:^
{
if (angle !=
0.0f){
self.subThemeGobackBtn.frame = CGRectMake(positionX, positionY, 0.0f,
0.0f);
}else{
self.subThemeGobackBtn.frame = CGRectMake(positionX, positionY, 120.0f,
23.0f);
self.buttonImageView.alpha =
1.0f;
}
}completion:^(BOOL
finished){
if (angle != 0.0f)
{
[UIView
animateWithDuration:0.0f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState
animations:^
{
self.subThemeGobackBtn.transform
=
CGAffineTransformMakeRotation(angle +
M_PI);
// Commit the
changes
[UIView
commitAnimations];
}completion:^(BOOL
finished){
CGFloat positiony =
self.centercell.frame.origin.y;
CGFloat positionx =
self.centercell.frame.origin.x;
if (self.centercell.frame.origin.y > self.collectionView.bounds.size.height /
2)
{
positiony = self.collectionView.bounds.size.height / 2 -
(self.centercell.frame.origin.y - self.collectionView.bounds.size.height / 2 ) -
65.0f
;
}else{
positiony = self.collectionView.bounds.size.height / 2 +
(self.collectionView.bounds.size.height / 2 -self.centercell.frame.origin.y) -
65.0f;
}
if (self.centercell.frame.origin.x > self.collectionView.bounds.size.width /
2)
{
positionx = self.collectionView.bounds.size.width -
130.0f;
}else{
positionx =
20.0f;
if ((4 < -angle ) && (-angle <
5))
{
positionx = self.collectionView.bounds.size.width /
2;
positiony = self.collectionView.bounds.size.height / 2 -
(self.centercell.frame.origin.y - self.collectionView.bounds.size.height / 2 ) -
70.0f
;
}
}
[UIView
animateWithDuration:0.0f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState
animations:^
{
self.buttonImageView.alpha =
1.0f;
self.subThemeGobackBtn.frame = CGRectMake(positionx, positiony, 0.0f,
0.0f);
}completion:^(BOOL
finished){
[UIView beginAnimations:nil
context:NULL];
[UIView
setAnimationDuration:0.25f];
self.subThemeGobackBtn.frame = CGRectMake(positionx, positiony, 120.0f,
23.0f);
[UIView
commitAnimations];
}];
}];
}
}];
}
uicollectionview 使用uibutton或者uiimageview实现旋转出现scale的问题,码迷,mamicode.com
uicollectionview 使用uibutton或者uiimageview实现旋转出现scale的问题
原文地址:http://www.cnblogs.com/lisa090818/p/3699800.html