私はビュー、UI要素などをプログラムで作成します。 ビューが追加または削除されたときにアニメーション化しようとしています。問題は、UIButton *ボタンだけがアニメートされ、アニメーションが間違っていることです。私はボタンのタイトルが上から来てボタン自体が画面の右から来ることを意味します。スイッチの表示中に奇妙なアニメーション
以下のコードAppDelegate.h
#import <UIKit/UIKit.h>
#import "TViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
TViewController *tv;
}
@property (strong, nonatomic) TViewController *tv;
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m を参照してください.....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
self.tv = [[TViewController alloc]initWithNibName:@"TViewController" bundle:nil];
self.window.rootViewController = self.tv;
[self.window makeKeyAndVisible];
return YES;
}
TViewController.h
#import <UIKit/UIKit.h>
#import "Elements.h"
@interface TViewController : UIViewController
{
Elements *el;
}
@property (nonatomic, retain) Elements *el;
@end
TViewController.m
-(void)loadView
{
self.view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
self.el = [[Elements alloc]
initWithNibName:@"Elements"
bundle:nil];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view.superview cache:YES];
[self.view addSubview:self.el.view];
self.view.backgroundColor = [UIColor grayColor];
[self.view removeFromSuperview];
[UIView commitAnimations];
}
Elements.m
self.view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
UILabel *howManyUsersLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, 300, 150)];
howManyUsersLabel.text = @"Label ...";
[self.view addSubview:howManyUsersLabel];
UIPickerView *playersPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(10, 150, 250, 100)];
playersPickerView.delegate = self;
playersPickerView.showsSelectionIndicator = YES;
[self.view addSubview:playersPickerView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(20, 370, 280, 50);
[button setTitle:@"Button" forState:UIControlStateNormal];
[self.view addSubview:button];
私はそれを手に入れます。 これは、addSubviewが使用されているときに表示するために適用できる唯一のアニメーションです。 – objlv
申し訳ありませんが、私はあなたのアニメーションコードを誤読しました - あなたは別の種類のアニメーションをやっていると思いました。私は私の答えを更新しました。 –
TViewController.mの更新されたコードを参照してください。私はアニメーションの変化に気付かなかった。 – objlv