我有以下适用于 UIImageView 之类的东西。我不确定 UIView 动画是否适用于包含的控制器?我知道我正在为视图的框架设置动画,但只是不确定这是否/应该工作(下面的代码只是概念验证)。但即使这样做了,以下内容也不起作用。关于为什么不的任何想法?
提前谢谢
编辑#1
我添加了一个屏幕截图,其中显示了一个黄色的自定义视图控制器,其中包含短语holla
。如您所见,下面的代码使框架动画化,而不是该视图控制器的元素。这是故意的吗?有解决方法吗?
#import "MyViewController.h"
@interface ViewController ()
@property (nonatomic, strong) MyViewController *firstIV;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
// lets add a few UIImageViews that we will animate
MyViewController *tmpFirstIV=[[MyViewController alloc] init];
tmpFirstIV.view.backgroundColor=[UIColor yellowColor];
tmpFirstIV.view.frame=CGRectMake(10.0f, 10.0f, 100.0f, 100.0f);
self.firstIV=tmpFirstIV;
[self addChildViewController:self.firstIV];
[self.view addSubview:self.firstIV.view];
[self.firstIV didMoveToParentViewController:self.firstIV];
-(void)updateAction:(id) sender{
NSLog(@"Here are some results");
if([self.updateButton.currentTitle isEqualToString:@"update this"]){
[UIView animateWithDuration:6.0f animations:^{ // yeah I know, long animation
self.firstIV.view.frame=CGRectMake(10.0f, 10.0f, 100.0f, 0.0f);
}];
[self.updateButton setTitle:@"make bigger" forState:UIControlStateNormal];
}else{
[UIView animateWithDuration:6.0f animations:^{ // equally long
self.firstIV.view.frame=CGRectMake(10.0f, 10.0f, 100.0f, 100.0f);
}];
[self.updateButton setTitle:@"update this" forState:UIControlStateNormal];
}
}
编辑2
似乎没有做任何事情......将研究这一层。
-(void)viewWillLayoutSubviews { [super viewWillLayoutSubviews];
CGRect viewBounds = self.view.bounds;
self.myLabel.frame = CGRectMake(100.0f,viewBounds.size.height-20.0f,50.0f,50.0f);
}