我想在视图加载时将我的按钮和标签移动到特定位置。起初一切都在中心,当它加载时,一切都应该扩展到指定的位置。我有这个,但图标和标签不动。如果我在同一个视图中创建一个按钮并将代码放入其中,它会起作用。
#import "DashViewController.h"
@interface DashViewController ()
@end
@implementation DashViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (IBAction)backb:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)loadanim:(id)sender{
[self moveIcons];
}
-(void)moveIcons{
CGRect framehi = homeIcon.frame;
framehi.origin.x = 15;
framehi.origin.y = 70;
CGRect framehl = homeLabel.frame;
framehl.origin.x = -8;
framehl.origin.y = 136;
CGRect framesmi = smediaIcon.frame;
framesmi.origin.x = 131;
framesmi.origin.y = 70;
CGRect framesml = smediaLabel.frame;
framesml.origin.x = 108;
framesml.origin.y = 136;
CGRect framemi = mediaIcon.frame;
framemi.origin.x = 249;
framemi.origin.y = 70;
CGRect frameml = mediaLabel.frame;
frameml.origin.x = 225;
frameml.origin.y = 136;
CGRect frameni = newsIcon.frame;
frameni.origin.x = 15;
frameni.origin.y = 211;
CGRect framenl = newsLabel.frame;
framenl.origin.x = -8;
framenl.origin.y = 277;
CGRect framebi = bullyIcon.frame;
framebi.origin.x = 131;
framebi.origin.y = 211;
CGRect framebl = bullyLabel.frame;
framebl.origin.x = 108;
framebl.origin.y = 277;
CGRect framespi = sportsIcon.frame;
framespi.origin.x = 249;
framespi.origin.y = 211;
CGRect framespl = sportsLabel.frame;
framespl.origin.x = 225;
framespl.origin.y = 277;
CGRect framesti = staffIcon.frame;
framesti.origin.x = 15;
framesti.origin.y = 355;
CGRect framestl = staffLabel.frame;
framestl.origin.x = -8;
framestl.origin.y = 421;
CGRect framehbi = handbookIcon.frame;
framehbi.origin.x = 131;
framehbi.origin.y = 355;
CGRect framehbl = handbookLabel.frame;
framehbl.origin.x = 108;
framehbl.origin.y = 421;
CGRect frameai = aboutIcon.frame;
frameai.origin.x = 249;
frameai.origin.y = 355;
CGRect frameal = aboutLabel.frame;
frameal.origin.x = 225;
frameal.origin.y = 421;
[UIView animateWithDuration:0.3 animations:^{
homeIcon.frame = framehi;
homeLabel.frame = framehl;
smediaIcon.frame = framesmi;
smediaLabel.frame = framesml;
mediaIcon.frame = framemi;
mediaLabel.frame = frameml;
newsIcon.frame = frameni;
newsLabel.frame = framenl;
bullyIcon.frame = framebi;
bullyLabel.frame = framebl;
sportsIcon.frame = framespi;
sportsLabel.frame = framespl;
staffIcon.frame = framesti;
staffLabel.frame = framestl;
handbookIcon.frame = framehbi;
handbookLabel.frame = framehbl;
aboutIcon.frame = frameai;
aboutLabel.frame = frameal;
}];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self moveIcons];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end