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

最新文章

  1. 解决Ubuntu Kylin 1610安装ANSYS17.2的NVIDIA显卡驱动问题
  2. MySQL高可用架构之MHA
  3. The different of mouseover and mouseenter
  4. BASH 漏洞修复
  5. CSS DIV 独占一行,清除左右两边的浮动
  6. 谷歌、百度、1万ip能赚多少钱?1000IP能够值多少钱呢?
  7. Unicode基本概念
  8. 30大最有影响力的Web设计与开发英文博客
  9. Linux文件空洞与稀疏文件 转
  10. 我们都忽略了Html5的力量,如果只看成一种技术就大错特错了!
  11. 【POJ3169 】Layout (认真的做差分约束)
  12. abc - zx
  13. JQUERY1.9学习笔记 之属性选择器(二) 包含选择器
  14. Trigger model Trigger expr_id in WorkFolow
  15. Javascript 文件操作(整理版)
  16. win10十周年更新后cent os 虚拟机无法连接到xshell
  17. WPF依赖属性2
  18. 【原创】自己动手实现JDK动态代理
  19. 判断是否是IE9浏览器的最短语句 var ie=!-[1,]
  20. vs2017 winform打包

热门文章

  1. python中enumerate()函数的用法
  2. CentOS6.5卸载openJDK和安装Sun JDK
  3. Web框架之Django_02基本操作(Django项目启动配置、数据库连接、orm、增删改查)
  4. Day13有参装饰器,三元表达式,匿名函数
  5. re--模块【转】
  6. angular 创建项目
  7. Appium+python自动化-环境搭建
  8. NYOJ 311 完全背包
  9. 九度oj 题目1214:丑数
  10. 九度oj 题目1151:位操作练习