无法弄清楚在雅虎天气应用程序中使用的uiview过渡

时间:2013-10-25 18:19:19

标签: ios iphone ios7 uianimation

我试图模仿城市之间的雅虎天气应用程序屏幕转换,我无法弄清楚它是什么过渡。任何线索?

我真的很感谢你的时间。 感谢

编辑:

我有一个带有子视图的slideView ctrler。 sliderview有一个图像,子视图有文本。当我进行滑动时,带有文本的文本视图必须移动并以较慢的速度拖动视图ctrler并且此实习生应该开始在下一个视图ctrler中拖动,这是滑块Ctrler的一个实例。

2 个答案:

答案 0 :(得分:1)

没有为您执行此操作的内置转换(我假设您正在讨论以与视图本身不同的速率转换其frame / center的图像)。你可能要自己写。需要对手势识别器和视图动画有一些基本的了解。

基本效果是在更改这些视图(或其超级视图)的center时,同时调整两个图像视图的frame属性。 (或者,您可以通过拥有contentModeUIViewContentModeCenter并只更改frame的图片视图来实现这一目标。)我建议您从一些简单的效果测试开始,然后从那里。

例如,我创建了一个具有两个图像视图的场景,其自动布局约束定义如下:

H:|[leftImageView][rightImageView]|
V:|[leftImageView]|
V:|[rightImageView]|

然后,我为leftImageView定义了一个宽度约束,并将其连接到该约束的IBOutlet,例如leftImageWidthConstraint。然后我有一个可以处理手势的UIPanGestureRecognizer,只需相应地更改此leftImageWidthConstraint(并且使用自动布局,框架的其余部分将自动为我计算):

- (void)handlePan:(UIPanGestureRecognizer *)gesture
{
    CGPoint translate = [gesture translationInView:gesture.view];
    static CGFloat width;

    if (gesture.state == UIGestureRecognizerStateBegan)
    {
        width = self.leftImageWidthConstraint.constant;
    }

    CGFloat newWidth = width + translate.x;

    if (newWidth < 0)
        newWidth = 0;
    else if (newWidth > self.view.bounds.size.width)
        newWidth = self.view.bounds.size.width;

    self.leftImageWidthConstraint.constant = newWidth;

    // if you let go, animate the views to their final position

    if (gesture.state == UIGestureRecognizerStateEnded)
    {
        // if more than half way, set left view's target width to take up full width, 
        // otherwise set left view's target width to zero

        if (newWidth > (self.view.bounds.size.width / 2.0))
            newWidth = self.view.bounds.size.width;
        else
            newWidth = 0;

        // animate the changing of the constraint (and thus the `frame`) accordingly

        self.leftImageWidthConstraint.constant = newWidth;
        [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
            [self.view layoutIfNeeded];
        } completion:nil];
    }
}

因此,当我平移时,两个图像在其剪切的帧内居中:

enter image description here

这是这个想法的一个非常基本的实现。但是,有大量的实现细节(自定义容器vs子视图,autolayout vs not等),所以在你回答其中一些问题之前,很难更具体。

答案 1 :(得分:0)

这不是默认值,但我在旧应用程序中实现了类似的

  1. 在您的视图和相应的检测集isFromLeftSide上注册手势

  2. 请致电以下。根据您的要求对此进行微调

     [self.view addSubview:mySlidingView];
            mySlidingView.frame = // set offscreen frame, in the direction you want it to appear from depending on flag isFromLeftSide
            [UIView animateWithDuration:8.0 
                             animations:^{
                                 mySlidingView.frame = // desired end location
                                    }];