0
我以编程方式创建视图,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 2012-02-05 16:34:30
对不起,我误解了你的动画代码 - 我以为你正在做一种不同类型的动画。我已经更新了我的答案。 – 2012-02-05 16:39:02
请参阅TViewController.m的更新代码。我没有注意到动画的任何变化。 – objlv 2012-02-05 16:44:37