天天看点

uicollectionview 使用uibutton或者uiimageview实现旋转出现scale的问题

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];

}];