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 calculateLabelPositionFromFixedPoin开发者_StackOverflow中文版tWithOffsetClockwiseInDegrees: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?
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];
}
精彩评论