2014-03-03 2 views
1

У меня есть UIView, и я хочу дать ему эффект, который заставляет его начинать с альфы 0, а затем, перемещаясь на 50 пикселей, анимируется, также изменяется на альфа 1. Как это можно сделать в Objective-C ?Как я могу угасать UIView во время его перемещения?

+1

Вы смотрели на документы для 'UIView' вообще? – rmaddy

ответ

0
[UIView animateWithDuration:1.0 animations:^{ 
    //here change position and alpha 
    CGRect newFrame = view.frame; 
    newFrame.origin.y += 50; 
    view.frame = newFrame; 
    view.alpha = 1.0; 
} completion:^(BOOL finished) { 
    //called when animation did finish. do what you want 
}]; 
+0

Не анимируйте альфу как 0, так и 1 внутри анимации. Он должен быть в 0 перед анимацией. Просто установите его в 1 в анимации. – rmaddy

+0

@rmaddy извините, я имею в виду набор альфа до 0 перед началом анимации =) –

0

https://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

Все о анимации. Все в порядке.

//something similar to what you want: 

- (IBAction)showHideView:(id)sender 
{ 
    // Fade out the view right away 
    [UIView animateWithDuration:1.0 
     delay: 0.0 
     options: UIViewAnimationOptionCurveEaseIn 
     animations:^{ 
      thirdView.alpha = 0.0; 
     } 
     completion:^(BOOL finished){ 
      // Wait one second and then fade in the view 
      [UIView animateWithDuration:1.0 
       delay: 1.0 
       options:UIViewAnimationOptionCurveEaseOut 
       animations:^{ 
        thirdView.alpha = 1.0; 
       } 
       completion:nil]; 
     }]; 
} 
0

Нечто подобное будет делать трюк:

UIView *box = [[UIView alloc] initWithFrame:CGRectMake(self.view.center.x, self.view.center.y, 100, 50)]; 
box.backgroundColor = [UIColor blackColor]; 
box.alpha = 0.0f; 
[self.view addSubview:box]; 


[UIView animateWithDuration:2.0f 
       animations:^{ 
        box.alpha = 1.0f; 
        CGRect frame = CGRectMake(self.view.center.x, self.view.center.y - 100, 100, 50); 
        [box setFrame:frame]; 
       }]; 
Смежные вопросы