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)
animatewithduration:0.0f
self.subthemegobackbtn.transform
=
cgaffinetransformmakerotation(angle +
m_pi);
// commit the
changes
commitanimations];
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
;
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 /
positionx = self.collectionview.bounds.size.width -
130.0f;
positionx =
20.0f;
if ((4 < -angle ) && (-angle <
5))
positionx = self.collectionview.bounds.size.width /
2;
70.0f
[uiview beginanimations:nil
context:null];
setanimationduration:0.25f];
}];