メインビューに追加したいこのサブビューがありますが、原点から展開します。Apple のドキュメントをいくつか読みましたが、どこが間違っているのかわかりません。フレームの原点をアニメーション化できます。つまり、どこからでもスライドインできますが、幅/高さはアニメーション化されていないようです。次のようにコードします。
[UIView beginAnimations:@"animateAddContentView" context:nil];
[UIView setAnimationDuration:0.4];
customView.frame= CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 0, 150);
[self.view addSubview:customView];
customView.frame= CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 310, 150);
[UIView commitAnimations];
また、次のように setFrame 部分だけをアニメーションに入れてみました。
customView.frame= CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 0, 150);
[self.view addSubview:customView];
[UIView beginAnimations:@"animateAddContentView" context:nil];
[UIView setAnimationDuration:0.4];
customView.frame= CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 310, 150);
[UIView commitAnimations];
しかし、それでもうまくいきません!
編集:
提案に従って、ブロックベースのアニメーションソリューションに移動しました。これは正確なコードです:
NSLog(@"yourview : %@",customView);
customView.frame= CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 0, 150);
NSLog(@"yourview : %@",customView);
[self.view addSubview:customView];
NSLog(@"yourview : %@",customView);
// [customView setFrame:CGRectMake( 0.0f, 480.0f, customView.frame.size.width, customView.frame.size.height)];
[UIView animateWithDuration:0.4
delay:0
options:UIViewAnimationCurveEaseInOut
animations:^ {
NSLog(@"yourview : %@",customView);
customView.frame = CGRectMake(self.view.frame.origin.x +5, self.view.frame.origin.y +5, 310, 150);
NSLog(@"yourview : %@",customView);
}completion:^(BOOL finished) {
}];
これはまだ何らかの理由で機能しません。私が見る可能性のある問題は次のとおりです。
- 特に 310 x 150 からこの customView を読み込んでいます
nib
が、これが問題を引き起こしている可能性があります。 - 私は正しいフレームワークをインポートしていませんが、このビューの frame.origin 部分をアニメーション化できるので、そうであるかどうかはわかりません...私はすべてインポートしたものを持っ
QuartzCore
ています。Core Graphics
ログの各ポイントで、正しい内容が示されています。たとえば、ターゲット フレームの前のサイズは 0、150 で、フレームを設定した後は 310、150 です。しかし、アニメーションは機能しません。