2013-04-25 48 views
6

Nếu bạn tạo một thương hiệu mới ứng dụng xem đơn và đặt mã này đằng sau một nút:Cách thêm chế độ xem phụ với hoạt ảnh lật?

UIView *blah = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)]; 
blah.backgroundColor = [UIColor grayColor]; 
[UIView transitionWithView:blah duration:1 
        options:UIViewAnimationOptionTransitionFlipFromRight 
       animations:^{ 
        [self.view addSubview:blah]; 
       } 
       completion:^(BOOL finished){ 

       }]; 

Các subview được bổ sung ngay lập tức không có hình ảnh động. Nếu bạn thêm subview đầu tiên sau đó cố gắng để animate nó ... bạn nhận được cùng một vấn đề.

UIView *blah = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)]; 
    [self.view addSubview:blah]; 
    [UIView transitionWithView:blah duration:1 
         options:UIViewAnimationOptionTransitionFlipFromRight 
        animations:^{ 
         blah.backgroundColor = [UIColor grayColor]; 
        } 
        completion:^(BOOL finished){ 

        }]; 

Làm thế nào để bạn tạo hoạt ảnh cho một lần xem phụ ngay sau khi thêm?

+0

gì xảy ra khi bạn sử dụng xem container thay vì blah [UIView transitionWithView: containerView ...] – guenis

+0

nếu tôi sử dụng self.view làm chế độ xem chuyển tiếp, sau đó nó lật toàn bộ màn hình và khi nó hoàn thành, chế độ xem phụ của tôi được hiển thị. Tôi muốn lật tiểu thuyết khi tôi đi xem. –

Trả lời

12

Bạn thường cần phải có thùng chứa mà chế các hình ảnh động là ở chỗ đã:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    CGRect frame = CGRectMake(0, 0, 100, 100); 

    _container = [[UIView alloc] initWithFrame:frame]; 
    _container.backgroundColor = [UIColor lightGrayColor]; 
    [self.view addSubview:_container]; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 

    UIView *subview = [[UIView alloc] initWithFrame:_container.bounds]; 
    subview.backgroundColor = [UIColor darkGrayColor]; 

    [UIView transitionWithView:_container 
         duration:1.0 
         options:UIViewAnimationOptionTransitionFlipFromRight 
        animations:^{ 
         [_container addSubview:subview]; 
        } 
        completion:NULL]; 
} 
+1

Vâng, điều đó đã hiệu quả. Chỉ cần tạo một thùng chứa subview được tải sẵn hoạt động rất tốt! Cảm ơn, Rob! –

+0

Bạn có thể thêm Vùng chứa và thực hiện chuyển đổi trong một cuộc gọi lại không? –

1

Đây là giá trị một thử:

UIView *blah = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)]; 
blah.backgroundColor = [UIColor grayColor]; 
[self.view addSubview:blah]; 
blah.alpha = 0.0; //Or with blah.hidden = TRUE and then FALSE inside the animation block 
[UIView transitionWithView:blah 
        duration:1 
        options:UIViewAnimationOptionTransitionFlipFromRight 
       animations:^{ 
        blah.alpha = 1.0; 
       } 
       completion:^(BOOL finished){ 

       }]; 
+0

lol, tôi đã thử nó quá nhưng không có lật, tuy nhiên, các subview không phai in Tôi thực sự cần lật. ; ( –

+0

Cảm ơn rất nhiều guenis alpha vẫn tạo ra sự kỳ diệu .. :) – Abo3atef

Các vấn đề liên quan