0
我有以下幾種工作正常的UIImageView。我不確定UIView動畫是否可以與包含的控制器一起使用?我知道我是動畫視圖的框架,但不知道這是否會/應該工作(下面的代碼只是概念驗證)。但即使這樣做,下面的工作也不起作用。任何想法爲什麼不呢?可以使用UIView動畫來爲包含的控制器設置動畫效果嗎?
THX提前
編輯#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];
}
}
EDIT2
似乎並沒有做任何事情......會考慮這一層。
- (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews];
CGRect viewBounds = self.view.bounds;
self.myLabel.frame = CGRectMake(100.0f,viewBounds.size.height-20.0f,50.0f,50.0f);
}
嗯......這可以在覈心動畫中完成,其中子視圖會波動地動畫? – timpone 2013-02-25 04:36:54
當然,但viewWillLayoutSubviews中的一行可以將標籤置於其超級視圖內... – 2013-02-25 04:45:19
好吧,我是一個主要的笨蛋。我試着用viewWillLayoutSubviews(見上面的編輯#2)更新,但沒有骰子。如果對我有什麼幫助,將不勝感激,但今天晚些時候會進行調查。 – timpone 2013-02-25 04:59:23