2013-03-15 124 views
0

我試圖動畫子視圖的框架,但它不工作:不能動畫子視圖的框架

[UIView animateWithDuration:0.5 
        animations:^{ 
        NSLog(@"BIIIM %@", [_subView subviews]); 
        UIImageView *imageView1 = (UIImageView *)[self.view viewWithTag:(1)];{ 
          imageView1.frame = CGRectMake(76.8 , -100, 33.4, 164); 
          imageView1.alpha = 0.5; 
                   } 

爲阿爾法的動畫工作得很好,但一個框架是不是...任何想法? 謝謝!

回答

0

我做了一個簡單的測試如下,並發現它工作正常。 alpha和frame都會改變。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; 
    imageView1.backgroundColor = [UIColor redColor]; 
    [self.view addSubview:imageView1]; 

    [UIView animateWithDuration:2 animations:^{ 
     imageView1.frame = CGRectMake(20, 20, 100, 100); 
     imageView1.alpha = 0.5; 
    }]; 

} 
+0

謝謝你的回答。這個問題與動畫沒有多大關係,因爲即使我試圖在沒有動畫的情況下更改imageView1的框架,它也不起作用......但是alpha可以工作。 :( – Carapuce 2013-03-15 00:41:59

+0

嗨,做了一個簡單的測試如下,並找到它工作正常的α和幀變化都 - (無效)viewDidLoad中 { [超級viewDidLoad中]; \t 的UIImageView * imageView1 = [[的UIImageView ALLOC] initWithFrame:方法CGRectMake(0,0,30,30)]; imageView1.backgroundColor = [的UIColor redColor]; [self.view addSubview:imageView1]; [UIView的animateWithDuration:2個動畫:^ { imageView1 .frame = CGRectMake(20,20,100,100); imageView1.alpha = 0.5; }]; } – 2013-03-15 00:53:55

+0

非常感謝流觴_iviedsky! 我認爲問題更多的是我的超級觀點不讓我的子視圖移動或類似的東西。我無法弄清楚爲什麼。 – Carapuce 2013-03-15 01:16:06