簡體   English   中英

如何在iOS中為x,y,高度,寬度和旋轉設置動畫?

[英]How can I animate x, y, height, width, and rotation in iOS?

Ray的UIView動畫教程中 ,以下代碼似乎可以完成野餐籃的頂部和底部的開口並顯示下面的內容:

- (void)viewDidAppear:(BOOL)animated
{

    CGRect basketTopFrame = self.basketTop.frame;
    basketTopFrame.origin.y = -basketTopFrame.size.height;

    CGRect basketBottomFrame = self.basketBottom.frame;
    basketBottomFrame.origin.y = self.view.bounds.size.height;

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:1.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    self.basketTop.frame = basketTopFrame;
    self.basketBottom.frame = basketBottomFrame;

    [UIView commitAnimations];
}

由此看來,basketFooFrame.origin.y是籃子元素將移動的正距離或負距離。 應該理解為定義“您設置了目標坐標,示例將運行嗎?”的方法。

我的目標是比上面的技巧更詳細的動畫; UIView具有特定的x,y,高度,寬度和旋轉度,我希望對其進行動畫處理,以使其緩和,使其在水平和垂直方向上居中,與視口一樣高,減去某些邊距,然后旋轉回默認值。方向(如果單擊,則恢復為先前的狀態)。

通過對上面的代碼進行更詳盡的復制,我會得到我想要的嗎?

提前致謝,

UIKit動畫主要是“設置並忘記它”。 但是,如果您要在某個地方做某事,然后又回到起點,那將需要兩個動畫塊,因為您不能簡單地說“從點0,0到點0, 0到點20,20”,您必須說“轉到點20,20,完成后,轉到點0,0”。 例:

#import <CoreGraphics/CoreGraphics.h>

#define degreesToRadians(x) (M_PI * x / 180.0)

// ...

[UIView animateWithDuration:.25 animations:^{
  CGAffineTransform t = CGAffineTransformIdentity;
  CGAffineTransformScale(t, 2.0, 2.0);
  CGAffineTransformRotate(t, degreesToRadians(45));

  myview.transform = t;

} completion:^(BOOL finished){
    NSLog(@"step 1 done");

    [UIView animateWithDuration:.25 animations:^{

      myview.transform = CGAffineTransformIdentity;

    } completion:^(BOOL finished) {

      NSLog(@"step 2 done");

    }];

}];

暫無
暫無

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

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