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的问题的更多相关文章

  1. iOS开发——UI基础-UIButton、UIImageView、UILabel的选择

    1.UILabel - UILabel的常见属性 @property(nonatomic,copy) NSString *text; 显示的文字 @property(nonatomic,retain) ...

  2. UIButton、UIImageView、UILabel的选择

    UIButton特点既能显示文字,又能显示图片(能显示2张图片,背景图片.内容图片)长按高亮的时候可以切换图片\文字直接通过addTarget...方法监听点击 UIImageView能显示图片,不能 ...

  3. ##DAY2 UILabel、UITextField、UIButton、UIImageView、UISlider

    ##DAY2 UILabel.UITextField.UIButton.UIImageView.UISlider #pragma mark ———————UILabel——————————— UILa ...

  4. UITextFiled,UIButton,UIImageView交互相互之间的事件拦截

    UIButton右上方添加一个笑button如: UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];    button.f ...

  5. IOS中UIButton和UIImageView的区别

    1.使用场合 UIImageView:如果仅仅是为了显示图片,不需要监听图片的点击事件 UIButton:既要显示图片,又要监听图片等点击事件 2.相同点 都能显示图片 3.不同点 UIButton能 ...

  6. UIButton和UIImageView的区别

    1.显示图片 1> UIImageView只能一种图片(图片默认会填充整个UIImageView)  image\setImage: 2> UIButton能显示2种图片 * 背景 (背景 ...

  7. UIButton和UIimageView

    1.按钮控件使用的类是UIButton 点击按钮会触发某个事件 2.按钮控件的初始化 UIButton *button = [UIButton buttonWithType:UIButtonTypeC ...

  8. css3 新特性(2D translate 移动,rotate 旋转 , scale 缩放)

    1.transform(转换)可以实现元素的位移,旋转,缩放等效果(可以简单理解为变形) 移动:translate            旋转:rotate          缩放:scale 2. ...

  9. iOS基础 - UIButton - UIImageView

    封装思想:将相同的重复东西保存到方法里,不同的东西用参数代替.不相同的东西交给方法调用者,相同东西自己搞定. 一.UIButton和UIImageView的区别 1.显示图片 1> UIImag ...

随机推荐

  1. web资源持续更新----20150213

    响应式设计创意收集网站:http://mediaqueri.es css禅意花园 http://www.csszengarden.com/

  2. html5/css3响应式页面开发总结

    一,自适应和响应式的区别 自适应是一套模板适应所有终端,但每种设备上看到的版式是一样的,俗称宽度自适应. 响应式一套模板适应所有终端,但每种设备看到的版式可以是不一样的. 虽然响应式/自适应网页设计会 ...

  3. phpstorm设置方法头信息备注

    一.目标,如下图,希望在方法上增加如下头信息备注 二.设置live template: 三.增加方法头信息备注,如下所示: * created by ${USER} at ${DATE} ${TIME ...

  4. eclipse中tab键设置

    1.点击 window->preference-,依次选择 General->Editors->Text Editors,选中右侧的 insert space for tabs;如下 ...

  5. pycharm的一些操作指令和技巧

    Alt+Enter 自动添加包Ctrl+t SVN更新Ctrl+k SVN提交Ctrl + / 注释(取消注释)选择的行Ctrl+Shift+F 高级查找Ctrl+Enter 补全Shift + En ...

  6. 用btrace定位问题

    btrace 截取方法出入参 用btrace的手法,网上有很多.简单记录下我自己的使用经历. btrace脚本: import static com.sun.btrace.BTraceUtils.ex ...

  7. GT使用说明

    GT文档:https://gt.qq.com/docs.html GT Android版的详细使用手册: https://gt.qq.com/docs/a/GTAndroidUserGuide.pdf

  8. appium之android_uiautomator定位进阶版

    前言 上一篇介绍uiautomator的定位方式都是类似这种'new UiSelector().xxx("xxx")',看起非常长,我也记不住,这很不python.于是本篇优化了定 ...

  9. 【Go】错误处理

    · error类型是一个接口类型,也是一个Go语言的内建类型.在这个接口类型的声明中只包含了一个方法Error.这个方法不接受任何参数,但是会返回一个string类型的结果.它的作用是返回错误信息的字 ...

  10. 九度oj 题目1159:坠落的蚂蚁

    题目描述: 一根长度为1米的木棒上有若干只蚂蚁在爬动.它们的速度为每秒一厘米或静止不动,方向只有两种,向左或者向右.如果两只蚂蚁碰头,则它们立即交换速度并继续爬动.三只蚂蚁碰头,则两边的蚂蚁交换速度, ...