2016-05-23 5 views
1

私はUIViewというloadingViewは、UIActivityIndicatorViewのようなアニメーションを示しています。すべてUIViewを持つ2つのUIViewControllerがあります。アニメーションが非初期のUIViewControllerで動作しない

初期UIViewControllerのコード:

- (void)viewDidLoad { 
    self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)]; 
    [self.view addSubview:self.loadingView]; 
} 

また、第2 UIViewControllerを提示するためのボタンを有する。

- (void)buttonPressed { 
    SecondViewController *sVC = [[SecondViewController alloc] init]; 
    [self presentViewController:sVC animated:YES completion:nil]; 
} 

ViewControllerviewDidLoad方法コード:

- (void)viewDidLoad { 
    self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)]; 
    [self.view addSubview:self.loadingView]; 
} 

可能な限り参照のこと、2つは、同じメソッドコードを持っています。

loadingViewは、最初のUIViewControllerでうまくいきます。

しかし、第2のUIViewControllerでは、loadingViewは黒いフレームのみを表示します(背景色を黒に設定します)。それは同様に存在モードで動作しますので

#define NUMBER_OF_DOT 15 
#define DURATION 1.5 

- (id)initWithFrame:(CGRect)frame { 
    self = [super initWithFrame:frame]; 

    if (self) { 
     self.replicatorLayer = [[CAReplicatorLayer alloc] init]; 
     self.replicatorLayer.frame = frame; 
     self.replicatorLayer.cornerRadius = 10.0; 
     self.replicatorLayer.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.86].CGColor; 
     self.replicatorLayer.position = self.center; 
     self.replicatorLayer.instanceDelay = DURATION/NUMBER_OF_DOT; 
     [self.layer addSublayer:self.replicatorLayer]; 

     float size = frame.size.width*14/200; 
     self.dot = [[CALayer alloc] init]; 
     self.dot.bounds = CGRectMake(0, 0, size, size); 
     self.dot.position = CGPointMake(frame.size.width/2, frame.size.height/5); 
     self.dot.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1.0].CGColor; 
     self.dot.borderColor = [UIColor whiteColor].CGColor; 
     self.dot.borderWidth = 1.0; 
     self.dot.cornerRadius = 1.5; 
     self.dot.transform = CATransform3DMakeScale(0.01, 0.01, 0.01);  
     [self.replicatorLayer addSublayer:self.dot]; 

     self.replicatorLayer.instanceCount = NUMBER_OF_DOT; 
     float angle = 2*M_PI/NUMBER_OF_DOT; 
     self.replicatorLayer.instanceTransform = CATransform3DMakeRotation(angle, 0.0, 0.0, 0.1); 

     self.shrink = [[CABasicAnimation alloc] init]; 
     self.shrink.keyPath = @"transform.scale"; 
     self.shrink.fromValue = [NSNumber numberWithFloat:1.0]; 
     self.shrink.toValue = [NSNumber numberWithFloat:0.1]; 
     self.shrink.duration = DURATION; 
     self.shrink.repeatCount = INFINITY; 

     [self.dot addAnimation:self.shrink forKey:nil]; 
    } 

    return self; 
} 
+0

この行の詳細を教えてください。 SecondViewController * sVC = [[HMPlaySceneViewController alloc] init]; HMPlaySceneViewController型オブジェクトを割り当て、SecondViewControllerクラスの参照を渡します。 – Shreyank

+0

@Shreyank私のせいです。私はコードを更新しました。 'SecondViewController'は非常に' HMPlaySceneViewController'です。私は 'HMPlaySceneViewController'の名前を変更して質問を単純化しましたが、コードを更新するのを忘れました。 – CokileCeoi

+0

コードを確認します。 View Controllerを表示するときに問題に直面します。しかし、私はviewcontrollerプッシュしようとするとうまく動作します。確認し、プレゼンテーションの問題点をお知らせします。 – Shreyank

答えて

0
-(void)viewDidAppear:(BOOL)animated 
{ 
    self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)]; 
    [self.view addSubview:self.loadingView]; 
} 

SecondViewControllerのviewDidAppearにこのコードを入れてください:

は、ここに私のloadingView実装するコードです。

+0

私はその理由も見つけました。私は 'viewDidLoad'でアニメーションを実行すべきではありません – CokileCeoi

+0

しかし、なぜアニメーションは最初の' UIViewController'でうまくいくのですか? – CokileCeoi

関連する問題