小编Jon*_*iVR的帖子

如何使用CrossDissolve幻灯片切换为Tab栏选项卡切换设置动画?

我试图在UITabBarController类似于Facebook应用程序上创建过渡效果.我设法得到一个"滚动效果"工作Tab键切换,但我似乎无法弄清楚如何交叉溶解(或它至少不起作用).

这是我目前的代码:

import UIKit

class ScrollingTabBarControllerDelegate: NSObject, UITabBarControllerDelegate {
    func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {

        return ScrollingTransitionAnimator(tabBarController: tabBarController, lastIndex: tabBarController.selectedIndex)
    }
}

class ScrollingTransitionAnimator: NSObject, UIViewControllerAnimatedTransitioning {
    weak var transitionContext: UIViewControllerContextTransitioning?
    var tabBarController: UITabBarController!
    var lastIndex = 0

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return 0.2
    }

    init(tabBarController: UITabBarController, lastIndex: Int) {
        self.tabBarController = tabBarController
        self.lastIndex = lastIndex
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        self.transitionContext = transitionContext

        let containerView = …
Run Code Online (Sandbox Code Playgroud)

uitabbarcontroller uitabbar ios swift

13
推荐指数
5
解决办法
2万
查看次数

将Swift项目转换为易于使用的Cocoapods框架

所以我需要一些帮助,因为我无法弄清楚它并且已经花了很多时间在它上面而没有任何结果.我在互联网上找到的大部分内容都是关于如何将一个快速项目转换为框架,但我的问题不是项目本身或cocoapods,而是关于我应该如何以及我应该让开发人员可以访问的内容.

所以我构建了一个Swift框架,你可以在这里找到它,它是UICollectionView用自定义flowlayout和侧面滑动功能构建的.

问题是,我不知道我怎样才能使这个易于使用的开发者,我想使它像一个UICollectionView在那里你需要实现一个自定义委托和数据源,而无需使用默认的UICollectionViewDelegateUICollectionViewDatasource,所以我可以过滤掉会导致意外行为的事情,或者只是保持简单.

那么这里有什么好方法呢?我正在考虑可能继承子类,UICollectionView所以人们不必使用a UICollectionView(因为这可能会让人感到困惑),而是一个VerticalCardSwiperView具有相同行为,但更有限的行为.我只是不知道这是否是正确的方法.

任何提示,见解或好的例子都将深表感谢!


编辑1:我更新了项目,因此它已经具有框架结构,我只需要弄清楚我将如何向开发人员提供对自定义部件的访问权限.

编辑2:我得到了一个答案,但我认为这个问题可能很容易被误解.目标是使其行为和行为像UICollectionView(与代表,数据源,...)但更有限,我想知道如何实现这一点,如果它甚至可能.

编辑3:好吧,我有大部分工作,我会在这里留下一个链接到Github在线,所以需要类似东西的人可以自己查看.从本质上讲,我所做的是定制VerticalCardSwiperDelegate,VerticalCardSwiperDatasource如下所示:

/// This datasource is used for providing data to the `VerticalCardSwiper`.
public protocol VerticalCardSwiperDatasource: class {

    /**
     Sets the number of cards for the `UICollectionView` inside the VerticalCardSwiperController.
     - parameter verticalCardSwiperView: The `VerticalCardSwiperView` where we set the amount of cards. …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch ios cocoapods swift swift-framework

7
推荐指数
1
解决办法
340
查看次数

UICollectionView scrollToItem()滚动到上一个单元格无法正常工作

在过去的几个星期里,我一直在打破这个问题,而且我的想法很糟糕......

背景短

UICollectionView使用自定义UICollectionViewFlowLayout垂直卡分页和创建卡堆栈效果构建了自己的框架.

这是它的外观的gif:

框架gif示例

问题

我正在尝试实现一个允许用户滚动到特定索引处的特定卡scrollToItem功能(例如使用该 功能).

现在的问题是,由于某种原因,当试图滚动回到前一张卡时,它无法正常工作.

下面是一个记录发生了什么,我已经附加了一个tapGestureRecognizer,当我点击焦点(当前居中)卡,它应滚动到该索引 - 1(所以前一张卡).
出于某种原因,只有frame.origin.y当底部卡片位于frame.origin.maxY聚焦(当前居中的卡片)之上时才会这样做.

问题演示gif

请注意,我在卡上点击两次以使其正常工作,因为frame.origin.y底卡的价值需要低于frame.origin.maxY顶卡的价值,因为它有效.

基本答案到目前为止我已经尝试过了

collectionView.scrollToItem(at: convertIndexToIndexPath(for: index), at: .top, animated: animated)
Run Code Online (Sandbox Code Playgroud)

if let frame = collectionView.layoutAttributesForItem(at: convertIndexToIndexPath(for: index))?.frame {
    collectionView.scrollRectToVisible(frame, animated: true)
}
Run Code Online (Sandbox Code Playgroud)

一些重要的事情要知道

我已经找出导致问题的那一行,在UICollectionViewFlowLayout(被调用VerticalCardSwiperFlowLayout)的子类中,有一个被调用的函数updateCellAttributes,它修改了帧的一些属性以便能够实现这种效果.问题发生在以下行:

let finalY = max(cvMinY, cardMinY)
Run Code Online (Sandbox Code Playgroud)

这是有问题的功能,包括对代码注释中顶部如何工作的非常扩展的解释:

/**
 Updates the attributes.
 Here manipulate the zIndex of …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch uikit ios uicollectionview swift

7
推荐指数
1
解决办法
528
查看次数

使 document.execCommand('insertText', false, 'message') 与 Draftjs 一起工作?

我正在开发一个需要将文本插入contenteditable="true"div的应用程序(Draftjs准确地说是基于文本字段)。

现在我知道 Draft.js 使用 react 并且应该以这种方式使用它,但在这种情况下,该应用程序已经存在并且这是一个与之配合使用的第三方电子应用程序。

我正在 macOS 上处理在线通知回复,因此我需要将该回复文本粘贴到 DraftJS 字段中,但是,当我这样做时,使用:

document.querySelector('div[contenteditable="true"]').focus();
document.execCommand('insertText', false, 'message');
Run Code Online (Sandbox Code Playgroud)

它抛出一个错误: 错误图像

我能够使用以下方法使其工作:

const event = document.createEvent('TextEvent');
event.initTextEvent('textInput', true, true, window, 'message', 0, locale);
Run Code Online (Sandbox Code Playgroud)

但如果消息包含表情符号,则此 API 已弃用且无法正常工作。

有没有办法做到这一点,不会导致错误?我发现应该替换 initTextEvent 的新 API 只是new Event()(参见文档),但我不知道它是否支持 textInput 事件。

要使用它,您可以访问https://draftjs.org/并在 chrome 开发工具中使用它。

我真的很感激这里的一些帮助,因为我不知道该怎么做才能让它继续工作。另外,我知道人们是 jquery 的粉丝,但我更喜欢原生 js 解决方案(尽管欢迎任何解决方案)。

编辑:

请注意:我没有使用 react,我想修改的输入字段 (draftjs) 使用的是 react,我想使用原生 js 向其中输入文本。

编辑2:

对于遇到此问题的其他人,我想将文本插入 Facebook 信使文本字段(使用 Draftjs)。

我设法找到了一个可行的解决方法。它确实使用了已弃用的 API ( event.initTextEvent),但这是我发现的唯一有效方法,即使使用表情符号也是如此。如果您对此有更好的解决方案,请发布答案。 它是这样工作的:

async function sendReply(message: …
Run Code Online (Sandbox Code Playgroud)

javascript execcommand reactjs electron draftjs

6
推荐指数
1
解决办法
3540
查看次数

如何更改UICollectionViewCell的初始布局位置?

背景

所以,我正在开发一个自定义框架,我已经UICollectionViewFlowLayout为我实现了一个自定义UICollectionView.实现允许您滚动卡片堆栈,同时向左/右刷卡(单元格)(Tinder + Shazam Discover组合).

我正在修改UICollectionViewLayoutAttributes以创建滚动卡堆栈效果.

问题

在堆栈结束时,当我刷卡(单元格)时,新卡不会从堆栈后面出现,而是从顶部出现.这只发生在堆栈的末尾,我不知道为什么.

我的想法 - 我尝试过的

我的猜测是我需要修改一些东西initialLayoutAttributesForAppearingItem,我已经尝试过,但它似乎没有做任何事情.

我正在调用其中的updateCellAttributes函数来更新属性,但我也尝试手动修改其中的属性.我真的没有在这里看到这个问题,除非有一种不同的方法来修改卡片在这种情况下的定位方式.

也许是因为细胞在技术上还不在"直肠"中(参见参考资料layoutAttributesForElements(in rect: CGRect)),它们不会更新?

有什么我想念的吗?是否有人更熟悉如何修改flowlayout以实现我想要的行为?

示例和代码

这是一个实际的GIF:

正常的例子

这是我想要解决的bug的gif:

错误的例子

如您所见,当刷掉最后一张卡时,新卡从顶部出现,而它应该从前一张卡的后面出现.

您可以在下面找到自定义UICollectionViewFlowLayout代码.最重要的功能是updateCellAttributes使用内联注释记录的功能(请参阅下面的代码).调用此函数:
initialLayoutAttributesForAppearingItem
finalLayoutAttributesForDisappearingItem
layoutAttributesForItem
layoutAttributesForElements
修改布局信息并创建堆栈效果.

import UIKit

/// Custom `UICollectionViewFlowLayout` that provides the flowlayout information like paging and `CardCell` movements.
internal class VerticalCardSwiperFlowLayout: UICollectionViewFlowLayout {

    /// This property sets the amount of scaling for the first item.
    internal var firstItemTransform: …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch ios uicollectionview swift

5
推荐指数
1
解决办法
534
查看次数