2014-05-21 12 views
0

我試圖給標籤和圖像視圖添加動畫,讓它們從無到有的增長到我在界面構建器中的大小和位置。使用CGAffineTransformMakeScale生長兩個控件的ios不能正確保持中心?

我的圖像視圖更大,標籤和標籤位於它的頂部。 是這樣的...

............................. 
.       . 
. ......................... . 
. .      . . 
. .  LABEL   . . 
. .      . . 
. ......................... . 
.       . 
.  IMAGE VIEW   . 
............................. 

我覺得中心點其中動畫應該從開始就標籤的中心。

這是我試過的,我可能想要添加更多的動畫,因此數組。

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    self.imv.transform = CGAffineTransformMakeScale(0.0, 0.0); 
    self.lbl.transform = CGAffineTransformMakeScale(0.0, 0.0); 

    NSMutableArray* animationBlocks = [NSMutableArray new]; 
    typedef void(^animationBlock)(BOOL); 
    animationBlock (^getNextAnimation)() = ^{ 
     animationBlock block = animationBlocks.count ? 
      (animationBlock)[animationBlocks objectAtIndex:0] : nil; 
     if (block){ 
      [animationBlocks removeObjectAtIndex:0]; 
      return block; 
     }else{ 
      return ^(BOOL finished){}; 
     } 
    }; 

    [animationBlocks addObject:^(BOOL finished){; 
     [UIView animateWithDuration:1.0 animations:^{ 
      //grow 
      self.lbl.hidden = NO; 
      self.lbl.transform = CGAffineTransformMakeScale(1.0, 1.0); 
      self.imv.hidden = NO; 
      self.imv.transform = CGAffineTransformMakeScale(1.0, 1.0); 

     } completion: getNextAnimation()]; 
    }]; 

    [animationBlocks addObject:^(BOOL finished){; 
     // 
    }]; 
    getNextAnimation()(YES); 
} 

我試過設置錨點和我也看了CGAffineTransformScale,但我不知道會在情況/迷茫的工作。

回答

0

您將不得不將尺度轉換與翻譯相結合。像

CGAffineTransformTranslate(CGAffineTransformMakeScale(0,0), self.imv.frame.size.width/2 , self.imv.frame.size.height/2); 
+0

但這樣做的標籤和圖像視圖? – Jules

+0

它只是分開工作,所以如果你爲兩者做,每一個都會從中心擴展。如果您希望同時進行縮放,則需要它們成爲同一父視圖的子視圖並縮放(簡單選項)。或者你必須計算所需的中心申請翻譯(多一點工作) – robert

+0

事情變得更簡單,當然,如果你的標籤被添加爲imageView的子視圖。那麼你只需要縮放imageView。 – robert