2013-04-22 43 views
0

我遇到了CGAffineTransformMakeScale问题。我使用下面的代码显示隐藏它的视图&。这是第一次显示&完全被驳回。但之后比它再没有出现。在我印刷日志之后,它实际上是走出屏幕coorediantes。CGAffineTransformMakeScale无法正常工作

我treid应用重置转换关闭,使用CGAffineTransformIdentity但仍然无法正常工作。下面

- (void) showWithAnimation 
    { 
     float mheight = customView.frame.size.height; 

     UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow; 

     if(!keyWindow) 
     { 
      NSArray *windows = [UIApplication sharedApplication].windows; 

      if(windows.count > 0) 
       keyWindow = [windows lastObject]; 

      keyWindow = [windows objectAtIndex:0]; 
     } 

     UIView *containerView = [[keyWindow subviews] objectAtIndex:0]; 

     CGRect frame = customView.frame; 
     frame.origin.y = -mheight; 
     customView.frame = frame; 

     NSLog(@"customView - %@", customView); 

     [containerView addSubview:customView]; 

     customView.alpha = 0; 
     customView.transform = CGAffineTransformMakeScale(0.01, 0.01); 
     customView.center = CGPointMake((ScreenBounds().size.width/2) - 24, ScreenBounds().size.height/2); 

     NSLog(@"customView After applying transfrom - %@", customView); 


     [UIView animateWithDuration:0.3 
           delay:0.0 
          options:UIViewAnimationCurveEaseInOut 
         animations:^{ 
          customView.transform = CGAffineTransformMakeScale(1, 1); 
           customView.alpha = 1; 
         } 
         completion:^(BOOL finished){ 

          self.isVisible = YES; 
          NSLog(@"customView Displayed ....."); 
          NSLog(@"customView - %@", customView); 
     }]; 
    } 

    - (void)dismissWithAnimation 
    { 
     [UIView animateWithDuration:0.3 
           delay:0.0 
          options:UIViewAnimationCurveEaseInOut 
         animations:^{ 
          customView.transform = CGAffineTransformMakeScale(0.01, 0.01); 
          customView.alpha = 0; 
         } 
         completion:^(BOOL finished) 
         { 
          self.isVisible = NO; 

**//Edit: I tried applying CGAffineTransformIdentity at here** 

          [customView removeFromSuperview]; 
         }]; 
    } 

是原木,

--> 1st time logs 

customView -> <UIView: 0x205a1e50; frame = (24 -150; 272 150); layer = <CALayer: 0x205a1eb0>> 

customView After applying transfrom - <UIView: 0x205a1e50; frame = (134.64 283.25; 2.72 1.5); transform = [0.01, 0, 0, 0.01, 0, 0]; alpha = 0; layer = <CALayer: 0x205a1eb0>> 

customView Displayed ..... 
customView - <UIView: 0x205a1e50; frame = (0 209; 272 150); layer = <CALayer: 0x205a1eb0>> 


--> 2nd time logs 

customView -> <UIView: 0x205a1e50; frame = (24 -204; 272 204); transform = [0.01, 0, 0, 0.01, 0, 0]; alpha = 0; animations = { transform=<CABasicAnimation: 0x2072c620>; opacity=<CABasicAnimation: 0x2072df20>; }; layer = <CALayer: 0x205a1eb0>> 

customView After applying transfrom - <UIView: 0x205a1e50; frame = (3.03984e-06 182; 272 204); transform = [0.01, 0, 0, 0.01, 0, 0]; alpha = 0; animations = { transform=<CABasicAnimation: 0x2072c620>; opacity=<CABasicAnimation: 
0x2072df20>; }; layer = <CALayer: 0x205a1eb0>> 

customView Displayed ..... 

customView - <UIView: 0x205a1e50; frame = (-13464 -9916; 27200 20400); layer = <CALayer: 0x205a1eb0>> 

什么在这里发生了拨错。

+0

何时/你在哪里申请CGAffineTransformIdentity休息转换矩阵? – 2013-04-22 11:32:34

+0

在dimissView中,我插入了有关该日志 – JiteshW 2013-04-22 11:39:40

回答

1

我总是检查是否动画结束......也重置动画开始之前......这样的事情...

// skipping some of ur code... 

    customView.transform = CGAffineTransformMakeScale(0.01, 0.01); 
     [UIView animateWithDuration:0.3 
           delay:0.0 
          options:UIViewAnimationCurveEaseInOut 
         animations:^{ 
          customView.transform = CGAffineTransformMakeScale(1, 1); 
           customView.alpha = 1; 
         } 
         completion:^(BOOL finished){ 
         if (finished) 
         { 

          customView.transform = CGAffineTransformMakeScale(1, 1); 
           customView.alpha = 1; 

          self.isVisible = YES; 
          NSLog(@"customView Displayed ....."); 
          NSLog(@"customView - %@", customView); 
         } 
     }]; 

//解雇动画

- (void)dismissWithAnimation 
{ 
    customView.transform = CGAffineTransformMakeScale(1.0, 1.0); 
    [UIView animateWithDuration:0.3 
          delay:0.0 
         options:UIViewAnimationCurveEaseInOut 
        animations:^{ 
         customView.transform = CGAffineTransformMakeScale(0.01, 0.01); 
         customView.alpha = 0; 
        } 
        completion:^(BOOL finished) { 
        if (finished) 
        { 
         self.isVisible = NO; 
         customView.transform = CGAffineTransformMakeScale(0.01, 0.01); 
         customView.alpha = 0; 
         [customView removeFromSuperview]; 
        } 

        }]; 
} 

//编辑 - 试试这个。

customView.alpha = 0; 

customView.transform = CGAffineTransformIdentity; //Reset the transformation... 
customView.transform = CGAffineTransformMakeScale(0.01, 0.01); 

customView.center = CGPointMake((ScreenBounds().size.width/2) - 24, ScreenBounds().size.height/2); 
+0

您可以告诉在动画和已完成的块中应用transfromation在同一视图上的区别。我尝试过,但我的问题仍然存在。 – JiteshW 2013-04-23 05:58:33

+0

完成块通过ua变量调用完成...动画可能已经完成,即使没有完全完成您想要的适当动画..即另一个视图出现在当前动画视图的顶部..然后检查完​​成== YES然后指定什么是当动画被认为完成时的最终状态......所以当动画视图回显时......它会出现在它应该在的位置。 – chuthan20 2013-04-23 14:46:55

+0

查看我对帖子所做的修改...并通过将其设置为showWithAnimation方法中的单位矩阵来重置转换。 – chuthan20 2013-04-23 15:03:10

0

使用下面的添加功能........

-(void) addSubViewWithPopUpAnimation:(UIView *)subView toView:(UIView *)containerView 
{ 
    [subView setTransform:CGAffineTransformMakeScale(0.1, 0.1)]; 

    [subView setAlpha:0.0f]; 

    [containerView addSubview:subView]; 

    [UIView animateWithDuration:0.3 animations:^ 
    { 
     [subView setTransform:CGAffineTransformMakeScale(1.15, 1.15)]; 
    } 
        completion:^(BOOL finished) 
    { 
     if(finished) 
     { 
      [UIView animateWithDuration:0.15 animations:^ 
       { 
        [subView setTransform:CGAffineTransformMakeScale(1.0, 1.0)]; 
        [subView setAlpha:1.0f]; 
       }]; 
     } 

    }]; 
} 

并用于去除........

-(void) removeSubViewWithPopUpAnimation:(UIView *)subView 
{ 
    [subView setAlpha:1.0f]; 

    [subView setTransform:CGAffineTransformMakeScale(1.0, 1.0)]; 

    [UIView animateWithDuration:0.3 animations:^ 
    { 
     [subView setTransform:CGAffineTransformMakeScale(0.01, 0.01)]; 
    } 
        completion:^(BOOL finished) 
    { 
     if(finished) 
     { 
      if([subView superview]) 
      { 
       [subView removeFromSuperview]; 
       [subView setAlpha:0.0f]; 
      } 
     } 
    }]; 


} 

这将是继功能绝对帮助你...........