zoukankan      html  css  js  c++  java
  • 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) {
                                 
                                 [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];
                                                                           
                                                                       }];
                                                      
                                                      
                                                  }];
                                 
                             }
                             
                         }];
        
    }

  • 相关阅读:
    实战SQL Server 2005镜像配置全过程
    Sql Server 主从数据库配置
    Windows server2003 + sql server2005 集群配置安装
    windows配置nginx实现负载均衡集群
    Nginx 在windows下配合iis搭建负载均衡过程 [转]
    服务器后端开发系列——《实战Memcached内存缓存系统》
    一步一步配置NLB(续)之深入测试
    一步一步配置NLB
    Hadoop MapReduceV2(Yarn) 框架简介[转]
    亿级Web系统搭建——单机到分布式集群[转]
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3699800.html
Copyright © 2011-2022 走看看