簡體   English   中英

將UIView動畫化為CGPoint

[英]Animating a UIView To A CGPoint

我想知道如何將UIView動畫化為特定的CGPoint。 以下是到目前為止我所擁有的(在當前狀態下不起作用):

#define MOVE_ANIMATION_DURATION_SECONDS 2

NSValue *pointValue = [[NSValue valueWithCGPoint:point] retain];
[UIView beginAnimations:nil context:pointValue];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:MOVE_ANIMATION_DURATION_SECONDS];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];

在開始之后但在提交之前,請更改UI視圖上的值。

嘗試:

#define MOVE_ANIMATION_DURATION_SECONDS 2

[UIView beginAnimations:nil context:pointValue];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:MOVE_ANIMATION_DURATION_SECONDS];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

CGRect frame = myUIViewObject.frame;
frame.origin = point;
myUIViewObject.frame = frame;

[UIView commitAnimations];

如果您的目標是10.5或更高,則可以通過添加到NSView的動畫代理來使用Core Animation。 嘗試

[[someView animator] setFrame: someNewFrame];

暫無
暫無

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

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