0

ビューの読み込み時に、ボタンとラベルを特定の場所に移動したいと考えています。最初はすべてが中央にあり、ロードするとすべてが指定された場所に展開されるはずです。私はこれを持っていますが、アイコンとラベルが動きません。同じビューでボタンを作成し、コードを配置すると機能します。

     #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
4

2 に答える 2

0

今のところ viewDidLoad からすべてを削除してから、viewDidAppear のコードを次のように変更します。

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    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;
    }];
}
于 2013-08-26T04:54:54.647 に答える