私は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];
}
第ViewController
のviewDidLoad
方法コード:
- (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;
}
この行の詳細を教えてください。 SecondViewController * sVC = [[HMPlaySceneViewController alloc] init]; HMPlaySceneViewController型オブジェクトを割り当て、SecondViewControllerクラスの参照を渡します。 – Shreyank
@Shreyank私のせいです。私はコードを更新しました。 'SecondViewController'は非常に' HMPlaySceneViewController'です。私は 'HMPlaySceneViewController'の名前を変更して質問を単純化しましたが、コードを更新するのを忘れました。 – CokileCeoi
コードを確認します。 View Controllerを表示するときに問題に直面します。しかし、私はviewcontrollerプッシュしようとするとうまく動作します。確認し、プレゼンテーションの問題点をお知らせします。 – Shreyank