双容器视图动画iOS [英] Dual Container View Animation iOS

查看:49
本文介绍了双容器视图动画iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个ViewController,它有两个Container View。最重要的是主要内容。底部的一面横幅将在某些事件上隐藏/显示。

So I've got a ViewController, which has two Container Views. The top one is the main content. The bottom one is a banner that will hide/show on certain events.

底部的位置使其位于选项卡栏下方,直到事件发生。

The bottom one is positioned such that it is under the tab bar until the event occurs.

事件发生时,主视图的框架缩小,横幅的框架重新定位,以使其看起来像滑入视图并变为可用。

When the event occurs, the frame of the main view is shrank and the frame of the banner is repositioned, such that it appears to 'slide' into the view and become available.

我遇到的问题是,除非我在情节提要中调整主视图的大小(这不是我想要的大小),否则我在代码中所做的任何调整大小都会显示横幅,但横幅无法响应触摸。 (在情节提要中调整大小,它的确会做出响应。)似乎前面还有其他一些视图可以拦截触摸,但是,什么以及如何解决呢?

The problem I'm having is, unless I resize the main view in the storyboard (which is not what I want), any resizing I do in code DOES reveal the banner, but the banner does not respond to touches. (Resizing in storyboard, it does respond.) It seems that there's some other view in front of it that's intercepting the touches, but what, and how do I fix it?

主视图控制器:

func hideBanner() {
    bannerViewController?.toggleBannerDisplay(show: false)
    contentTableViewController?.toggleBannerDisplay(show: false)
}
func showBanner() {
    bannerViewController?.toggleBannerDisplay(show: true)
    contentTableViewController?.toggleBannerDisplay(show: true)
}

内容表视图控制器:

func toggleBannerDisplay(show: Bool) {
    let tableView = self.view as! UITableView

    UIView.animate(withDuration: 0.5, animations: {
        if self.cancelApplyShowing == false && show == true {
            let frame = tableView.frame
            let newFrame = CGRect(x:frame.origin.x , y: frame.origin.y, width: frame.size.width, height: frame.size.height - 48)
            tableView.contentSize = newFrame.size
            tableView.frame = newFrame
            self.cancelApplyShowing = true
        } else if self.cancelApplyShowing == true && show == false {
            let frame = tableView.frame
            let newFrame = CGRect(x:frame.origin.x , y: frame.origin.y, width: frame.size.width, height: frame.size.height + 48)
            tableView.contentSize = newFrame.size
            tableView.frame = newFrame
            self.cancelApplyShowing = false
        }
    })
}

横幅:

func toggleBannerDisplay(show: Bool) {
    UIView.animate(withDuration: 0.5, animations: {
        if self.cancelApplyShowing == false && show == true {
            let frame = self.view.frame
            let newFrame = CGRect(x: frame.origin.x, y: frame.origin.y - 48, width: frame.size.width, height: frame.size.height)
            self.view.frame = newFrame
            self.cancelApplyShowing = true
        } else if self.cancelApplyShowing == true && show == false {
            self.view.frame.origin.y += 48
            self.cancelApplyShowing = false
        }
    })
}

由于某种原因,如果我调整主视图的大小,则隐藏的视图会变得响应(当然在动画之后)。

For some reason, if I resize that main view, the hidden view becomes responsive (after animations of course).

Vimeo视频: https://vimeo.com/246496442

推荐答案

我正在尝试使嵌入式视图控制器的视图动画化,这确实使所有内容都摆放到位,但是容器视图仍在顶部看不见。

I was trying to animate the embedded view controller's views, which did bring everything up and into place, but the container view was still sitting invisibly over the top.

I 动画化了容器视图,现在一切正常。

I animated the container views and everything works fine now.

这篇关于双容器视图动画iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆