繁体   English   中英

UIPickerView动画在屏幕上和屏幕外的行为

[英]UIPickerView Animate on and off screen behavior

这是这个问题的延续

CGRectMake:如何为UIPickerView动画计算X和Y?

https://stackoverflow.com/users/2315974/danypata回答

我有一个选择器视图,我想在按钮按下时在屏幕上和屏幕外制作动画,并使用上一个问题/答案中的代码,让我在第一次按下按钮时在屏幕上制作动画。

第二次按下按钮时,它消失了,而第三次按下时,它动画到了错误的位置...请帮助

编码

if (self.pickerSort.hidden == NO) {


    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        self.pickerSort.frame = CGRectMake(0,self.view.frame.size.height
                                           +  self.pickerSort.frame.size.height,-self.pickerSort.frame.size.width,-self.pickerSort.frame.size.height);
    }
                     completion:^(BOOL finished) {
                     }];
    self.pickerSort.hidden = YES;
   // [self performSelector:@selector(hidePicker) withObject:nil afterDelay:1];

} else if (self.pickerSort.hidden == YES) {

    self.pickerSort.hidden = NO;

    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        self.pickerSort.frame = CGRectMake(0 ,
                                       self.view.frame.size.height
                                       -  self.pickerSort.frame.size.height,
                                       self.pickerSort.frame.size.width,
                                       self.pickerSort.frame.size.height);
    }
                     completion:^(BOOL finished) {
                     }];
    [self.view bringSubviewToFront:self.pickerSort];

图像中的行为-按下按钮可以将动画精美地呈现到屏幕上

在此处输入图片说明

第二次按下它消失没有动画

第三按它动画到这里

在此处输入图片说明

任何帮助都会很棒...我正在寻找的功能是如何将选择器视图放回动画中,因此第三次按下与第一次按下相同

请尝试使用以下代码。

    self.pickerSort.hidden = NO;
    NSTimeInterval duration = 0.5;
    [UIView animateWithDuration:duration
                          delay:0
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{
                         CGRect pickerFrame = self.pickerSort.frame;

                         // currently picker is off the screen, show it.
                         if (pickerFrame.origin.y == self.view.frame.size.height) {
                             // set frame to show picker
                             pickerFrame.origin.y = self.view.frame.size.height - self.pickerSort.frame.size.height;
                         } else {
                             // set frame to hide picker
                             pickerFrame.origin.y = self.view.frame.size.height;
                         }
                         self.pickerSort.frame = pickerFrame;
                     }
                     completion:^(BOOL finished) {
                         self.pickerSort.hidden = YES;
                     }];

在研究了这一点并了解了框架和CGRect的来龙去脉之后,我通过使用以下代码实现了这一点

  if (pickerSort.hidden == YES) {
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        pickerSort.hidden = NO;

        visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
        [self.tableStations addSubview:visualEffectView];
        pickerSort.frame = CGRectMake(0,0,originalPickerFrame.size.width,originalPickerFrame.size.height);
        visualEffectView.frame = CGRectMake(0,0,originalPickerFrame.size.width,originalPickerFrame.size.height - 64);
    }
                     completion:^(BOOL finished) {

                         self.navigationController.navigationItem.leftBarButtonItem.enabled = NO;

                     }];
}
else
{
    visualEffectView.hidden = YES;
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{

        pickerSort.frame = CGRectMake(0,-originalPickerFrame.size.height,0,0);
    }
                     completion:^(BOOL finished) {

                         self.navigationController.navigationItem.leftBarButtonItem.enabled = YES;
                         pickerSort.hidden = YES;

                     }];
}

我像这样在viewDidLoad中设置原始帧大小

 pickerSort = [[UIPickerView alloc]initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
originalPickerFrame = pickerSort.frame;

pickerSort.frame = CGRectMake(0,-originalPickerFrame.size.height,0, 0);

希望这可以在将来对某人有所帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM