码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-07-22 23:16:32      阅读:455      评论:0      收藏:0      [点我收藏+]

标签:color   使用   os   width   io   for   

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的问题,码迷,mamicode.com

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

标签:color   使用   os   width   io   for   

原文地址:http://www.cnblogs.com/lisa090818/p/3699800.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!