如何获得目标 UITraitCollection 以及目标矩形

问题描述

我有一个工具窗格,在紧凑 H 模式下,它将位于底部,横跨全屏,但在紧凑 V 模式(或非紧凑 H 模式)中,它将作为浮动窗格位于右侧。如何获得目标 uitraitcollection + 目标大小?他们似乎有两种不同的方法

if (message.content.startsWith("s!kick")) {
    if (!message.guild.member(message.author).hasPermission("KICK_MEMBERS")) {
        return message.channel.send('You do not have the permission for kick users!');
    }
    if (!message.guild.member(client.user).hasPermission("KICK_MEMBERS")) {
        return message.channel.send("I don’t have the permission for kick users!");
    }
    if (message.mentions.users.size === 0) {
        return message.channel.send("You need to ping a user or the user can't be found!");
    }
    var member = message.mentions.members.first();
    member
        .kick()
        .then(member => {
            message.channel.send(member.displayName + " has been successfully kicked");
        })
        .catch(() => {
            message.channel.send("Sorry,you can't kick this member");
        });
    }

我需要这两个信息才能正确设置动画!非常感谢!

解决方法

实际上,通过对 UIViewControllerTransitionCoordinator 进行操作,您可以在两种方法中获得两个值、大小和特征集合。

let didQueueAnimation = coordinator.animate(alongsideTransition: { context in
    guard let view = context.view(forKey: UITransitionContextViewKey.to) else { 
        return
    }
    let newScreenSize = view.frame.size
    guard let viewController = context.viewController(forKey: UITransitionContextViewKey.to) else { 
        return
    }
    let newTraitCollection = viewController.traitCollection // <-- New Trait Collection
    // You can also get the new view size from the VC:
    // let newTraitCollection = viewController.view.frame.size

    // Perform animation if trait collection and size match.

},completion: { context in
    // Perform animation cleanup / other pending tasks.
})

if (didQueueAnimation) {
    print("Animation was queued.")
}

Apple 的想法是通过一个上下文参数简化调用站点,该参数可以查询多个属性,并且还异步执行,以便可以准确获取最终转换视图或 VC 的值甚至在更新发生之前就在一处。

虽然您可以使用 WillTransition 方法之一执行动画,但如果可能,我会使用 coordinator.animate(alongsideTransition:completion:) 方法而不是 coordinator.notifyWhenInteractionChanges(_:),因为它将系统动画与您自己的自定义动画同步,并且您仍然可以使用上述技术为新的 contexttraitCollection 查询 frame.size

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...