iPhone 4 在呈现视图时播放动画

发布于 2024-12-08 23:51:34 字数 1406 浏览 0 评论 0原文

我想将按钮放置在我的视图中围绕固定点的圆圈中。我可以这样做:

 button.layer.anchorPoint = CGPointMake(offsetX/button.frame.size.width, offsetY/button.frame.size.height);

button.transform = [self calculateLabelPositionFromFixedPointWithOffsetClockwiseInDegrees:commonAngleRatio*startSpacing*spacingRatio++];

其中calculateLabelPositionFromFixedPointWithOffsetClockwiseInDegrees:angleInDegrees是我编写的一个函数,用于给我CGAfflineTransformMakeRotation。

我希望按钮在呈现视图时以动画方式“轨道”到正确的位置。我尝试放置一个计时器,将动画调用到“viewWillAppear”中,但它似乎不起作用。

编辑:我对 UIViewController 进行了两次子类化:

@interface HomeScreenAbstractParentController : UIViewController<UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate, ContextActionDelegate, RemoteControlDelegate> {...}

并且

@interface AnimatedController : HomeScreenAbstractParentController
{}

在 AnimatedController 中,不会调用以下方法。我将 AnimatedController 的视图添加到 homeScreenController 的背面(如天气应用程序中),当用户按下按钮时,视图会翻转到其背面。完成此操作后,背面应该为控件设置动画。

-(void)viewWillAppear:(BOOL)animated

{
    NSLog(@"viewWillAppear");
    [super viewWillAppear:animated];

}


-(void)viewDidAppear:(BOOL)animated
{ 
    NSLog(@"viewDidAppear");
    [super viewDidAppear:animated];
    [self animateControls:nil];


}

在上述应用程序生命周期的哪个时刻,我应该安排计时器将按钮动画化到相应位置?是我翻转视图的时候吗?

I want to position buttons within my view in a circle around a fixed point. I can do this with :

 button.layer.anchorPoint = CGPointMake(offsetX/button.frame.size.width, offsetY/button.frame.size.height);

button.transform = [self calculateLabelPositionFromFixedPointWithOffsetClockwiseInDegrees:commonAngleRatio*startSpacing*spacingRatio++];

Where the calculateLabelPositionFromFixedPointWithOffsetClockwiseInDegrees:angleInDegrees is a function that I wrote to give me CGAfflineTransformMakeRotation .

I would like the buttons to animate "orbiting" into the correct position when the view is presented. I tried putting a timer that will call animation into "viewWillAppear", but it doesn't seem to work.

Edit: I'm subclassing a UIViewController twice:

@interface HomeScreenAbstractParentController : UIViewController<UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate, ContextActionDelegate, RemoteControlDelegate> {...}

and

@interface AnimatedController : HomeScreenAbstractParentController
{}

Within the AnimatedController the following methods do not get called. I have the AnimatedController's view added to the back of the homeScreenController (as in Weather app), and when a user presses a button, the view flips to it's backside. The backside should animate controls when this is done.

-(void)viewWillAppear:(BOOL)animated

{
    NSLog(@"viewWillAppear");
    [super viewWillAppear:animated];

}


-(void)viewDidAppear:(BOOL)animated
{ 
    NSLog(@"viewDidAppear");
    [super viewDidAppear:animated];
    [self animateControls:nil];


}

At which point in the lifecycle of the app above would I schedule the timer to animate buttons into positions? Is it when I flip the view over?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝礼 2024-12-15 23:51:34

在你的 viewController 中:

-(void)viewDidAppear {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1]; //amount of seconds animation should run
button.transform = [self calculateLabelPositionFromFixedPointWithOffsetClockwiseInDegrees:commonAngleRatio*startSpacing*spacingRatio++];
[UIView commitAnimations];


}

in your viewController :

-(void)viewDidAppear {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1]; //amount of seconds animation should run
button.transform = [self calculateLabelPositionFromFixedPointWithOffsetClockwiseInDegrees:commonAngleRatio*startSpacing*spacingRatio++];
[UIView commitAnimations];


}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文