2017-02-09 4 views
1

У меня есть один Uibutton в Buttom. когда пользователь нажимает на эту кнопку, анимация uiview отображается как всплывающее окно с buttom to up. это мой кодСоздайте тень (или размытие), когда пользователь нажимает на UIbutton?

-(void)viewDidLoad 
{ 
    [super viewDidLoad];  
    self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 1000, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height);  
} 

- (IBAction)animated:(id)sender 
{ 
    if(_isAnimated) 
    { 
     [UIView animateWithDuration:0.3 
          delay:0.0 
         options: UIViewAnimationOptionCurveEaseIn 
        animations:^{ 
         self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 520, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height); 
        } 
        completion:^(BOOL finished){ 
        }]; 
     _isAnimated=NO; 
    } 
    else 
    { 
     [UIView animateWithDuration:0.3 
          delay:0.0 
         options: UIViewAnimationOptionCurveEaseIn 
        animations:^{ 
         self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 1000, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height); 
        } 
        completion:^(BOOL finished) 
        { 

     }]; 
     _isAnimated=YES; 
    } 
} 

UIView анимация отлично работает, но когда UIView появляются, чем фон зрение создает тень (или размытость), как UIActionSheet и после законченного вида анимации фона ясно. Я не знаю, как реализовать. плз помочь мне Я новичок в КСН ...

+0

Вместо этого вы можете использовать два изображения, выбранные и нормальные, и соответственно изменить их, если анимация не требуется –

+0

спасибо за ваше предложение .. –

ответ

0

добавить свой код в viewdidload.add рамках QuartzCore

#import <QuartzCore/CAAnimation.h> 

self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 1000, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height); 
CABasicAnimation *animate = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"]; 
animate.fromValue = [NSNumber numberWithFloat:1.5]; 
animate.toValue = [NSNumber numberWithFloat:0.5]; 
animate.duration = 1.0; 
[self.BuyButtonPopUpView.layer addAnimation:animation forKey:@"shadowOpacity"]; 
self.BuyButtonPopUpView.layer.shadowOpacity = 0.0; 
0

Вы можете добавить UIView в фоновом режиме и установить его backgroundcolor черный и alpha 0,5 в раскадровке. Затем измените его alpha от 0,5 до 0 с анимацией. Вы также можете добавить UITapGestureRecognizer для обнаружения кранов на нем и рассеять представление, когда пользователь выходит наружу.

-(void)viewDidLoad 
{ 
    [super viewDidLoad];  
    self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 1000,  self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height);  
} 

- (IBAction)animated:(id)sender 
{ 
    if(_isAnimated) 
    { 
     [UIView animateWithDuration:0.3 
         delay:0.0 
        options: UIViewAnimationOptionCurveEaseIn 
       animations:^{ 
        self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 520, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height); 
        //showing background view here 
        self.viewBackground.alpha = 0.5; 
       } 
       completion:^(BOOL finished){ 
       }]; 
     _isAnimated=NO; 
    }  
    else 
    { 
     [UIView animateWithDuration:0.3 
         delay:0.0 
        options: UIViewAnimationOptionCurveEaseIn 
       animations:^{ 
        self.BuyButtonPopUpView.frame = CGRectMake(self.BuyButtonPopUpView.frame.origin.x, 1000, self.BuyButtonPopUpView.frame.size.width,self.BuyButtonPopUpView.frame.size.height); 
        //dismissing background view here 
        self.viewBackground.alpha = 0.0; 
       } 
       completion:^(BOOL finished) 
       { 

       }]; 
     _isAnimated=YES; 
    } 
} 

Для обнаружения краны снаружи и отклоняя Ваше мнение:

Создать UITapGestureRecognizer:

@interface ViewController() 
{ 
    UITapGestureRecognizer *tapGesture; 
} 

Инициализировать его в ViewDidLoad:

-(void)viewDidLoad 
{ 
    //defining your gesture method 
    tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTapGesture:)]; 

    //adding gesture recognizer on the background view 
    [self.backgroundView addGestureRecognizer:tapGestureRecognizer]; 
} 

В вашей Gesture распознаватель Метод:

-(void)handleSingleTapGesture:(UITapGestureRecognizer *)tapGestureRecognizer 
{ 
     [UIView animateWithDuration:0.3 
      animations:^{ 
       //dismissing background view here 
       self.viewBackground.alpha = 0.0; 
      } 
      completion:^(BOOL finished){ 
      }]; 
} 

Надеюсь, это поможет.

+0

спасибо ... его работы –

Смежные вопросы