簡體   English   中英

使UIButton imageView比框架更大,然后回到原來的尺寸?

[英]make a UIButton imageView Bigger than the frame and then back to its original size?

我想讓UIButton圖像從當前大小轉換為其大小的兩倍,然后回到原始大小,類似於facebook“like”動畫。

我正在使用此代碼但由於某種原因它正在執行相反的操作; 即先縮小,然后再變大。

我究竟做錯了什么? 它在uiimageView上運行完美,但在uibuttonuiimageViewuibutton

[self.likeButton setClipsToBounds:NO];
CGAffineTransform firstTransform = self.likeButton.imageView.transform;
[UIView animateWithDuration:.15f animations:^{

    self.likeButton.imageView.transform = CGAffineTransformScale(firstTransform, 2, 2);

} completion:^(BOOL finished) {

    [UIView animateWithDuration:.15f animations:^{

        self.likeButton.imageView.transform = firstTransform;
    }];
}];

圖層具有屬性masksToBounds和UIView具有clipsToBounds 很可能按鈕在主視圖或子視圖上將這些設置為YES。 您可以發現哪些設置為YES,並將它們暫時設置為NO。

如果有人有興趣我通過在按鈕上方添加uiimageview並對其進行動畫處理而不是按鈕圖像來解決它。

它是一個黑客但它的工作。

//設置button.masktobound = NO

[UIView animateWithDuration:.15f animations:^{

 self.likeButton.imageView.transform = CGAffineTransformMakeScale(2.0,2.0);

} completion:^(BOOL finished) {

[UIView animateWithDuration:.15f animations:^{

    self.likeButton.imageView.transform = CGAffineTransformMakeScale(1.0,1.0);
}];
}];

//嘗試這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM