小编Wii*_*ard的帖子

交互过渡不是线性的

我正在玩自定义和交互式视图控制器转换UIPercentDrivenInteractiveTransition.我正在构建一个以模态方式呈现卡片(其他视图控制器)的应用程序.我已经进行了自定义转换,UIViewControllerAnimatedTransitioning这使得卡片视图控制器的动画效果与标准模型演示风格非常相似.

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    {...}
    let fullScreenFrame = transitionContext.finalFrame(for: cardVC)
    let offsetFrame = cardVC.view.frame.offsetBy(dx: 0, dy: cardVC.view.frame.height)
    let finalFrame = presenting ? fullScreenFrame : offsetFrame
    cardVC.view.frame = presenting ? offsetFrame : fullScreenFrame
    containerView.addSubview(cardVC.view)

    UIView.animateKeyframes(
        withDuration: transitionDuration(using: transitionContext),
        delay: 0,
        options: UIViewKeyframeAnimationOptions.calculationModeLinear,
        animations: {
            UIView.addKeyframe(
                withRelativeStartTime: 0,
                relativeDuration: 1,
                animations: { [weak self] in
                    guard let strongSelf = self else { return }
                    backgroundView.alpha = strongSelf.presenting ? 1 : 0
            })

            UIView.addKeyframe(
                withRelativeStartTime: 0,
                relativeDuration: …
Run Code Online (Sandbox Code Playgroud)

interactive transitions uiviewanimation ios swift

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

UICollectionView:reloadData()导致单元格消失

我有一个自定义布局的collectionView,到目前为止我只有一个UICollectionReusableView.起初一切正常:

  1. prepareLayout() 被称为填充缓存,
  2. collectionViewContentSize() 被调用并返回正确的cententSize和
  3. layoutAttributesForElementsInRect() 被调用并返回正确的属性.

这会导致viewForSupplementaryElementOfKind调用collectionView的-method,之后视图变为可见.

稍后,当我按下按钮时,可重用视图的大小会更改,并被collectionView.reloadData()调用.这会导致再次调用上面提到的3个方法,并且它们仍然会返回具有新大小的正确值,但这次它不会触发viewForSupplementaryElementOfKind,并且collectionView变为空.

为什么不viewForSupplementaryElementOfKind叫?


调试示例:

layoutAttributesForElementsInRect第一次收集视图的返回(即工作时)

layout attributes: [<UICollectionViewLayoutAttributes: 0x7fa5005dc970> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (0 0; 414 1106); ]
Run Code Online (Sandbox Code Playgroud)

layoutAttributesForElementsInRect第二次返回集合视图的布局(即当它不起作用时)

layout attributes: [<UICollectionViewLayoutAttributes: 0x7fa500708f00> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (0 0; 414 1560.67); ]
Run Code Online (Sandbox Code Playgroud)

编辑:调试:

我刚刚测试使用collectionView.reloadData() …

ios uicollectionview uicollectionviewlayout swift

5
推荐指数
0
解决办法
866
查看次数

确定 UITextView 将截断字符串的位置

我有一个UITextView很长的字符串。文本视图大小由自动布局决定,并设置为尾截断文本。它看起来像这样:

UITextView 截断

如何确定显示的字符串范围和被截断的范围?

string uitextview ios autolayout swift

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

不称为境界迁移

我已经为一个领域对象添加了一个值(我已将动态var inspectorName =""添加到WeekReport对象中),我正在尝试迁移领域数据库以包含该值.我试图func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil)像这样调用迁移块:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    print("HERE")
    Realm.Configuration.defaultConfiguration = Realm.Configuration(
        schemaVersion: 1,
        migrationBlock: { migration, oldSchemaVersion in
            if (oldSchemaVersion < 1) {
                migration.enumerateObjects(ofType: WeekReport.className()) { oldObject, newObject in
                    newObject!["inspectorName"] = ""
                }
            }
    })

    return true
}
Run Code Online (Sandbox Code Playgroud)

但似乎didFinishLaunchingWithOptions在我的错误发生之前没有调用.

在多视图控制器中我有let realm = try! Realm().我运行应用程序时Xcode中断了:

"由于以下错误,需要迁移: - 已添加属性'WeekReport.inspectorName'." UserInfo = {NSLocalizedDescription =由于以下错误而需要迁移: - 已添加属性'WeekReport.inspectorName'.,错误代码= 10}:file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang- 800.0.63/src目录/快捷/

怎么没有调用迁移blick? …

migration realm ios swift

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

获取 KeyPath 的特定 CodingKey

考虑以下对象:

struct User: Codable {
    let id: Int
    let email: String
    let name: String
}
Run Code Online (Sandbox Code Playgroud)

是否有可能获得CodingKey给定的特定信息KeyPath

let key = \User.name.codingKey  // would be equal to string: "name"
Run Code Online (Sandbox Code Playgroud)

key-value-coding ios swift swift4 codable

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

Xcode:仅在默认状态下设置图像按钮,而不是也选择

我是Xcode和iPhone编程的新手.我有一个简单的问题,这让我烦恼..我想在一个按钮上设置一个图像,因为它是默认状态.所以我选择了按钮,在"显示属性检查器"选项卡中,我选择"状态配置"为默认值,然后在"图像" - 下拉列表中找到所需的图像...

问题:

我将"状态配置"更改为选中,图像仍然打开.我需要图像仅在默认状态下打开.如果我想在默认和选择状态下标题文本的字体大小不同,我也有同样的问题.我正在使用Xcode 4.6并为iOS 6.1编写.

xcode selected uibutton ios

4
推荐指数
1
解决办法
1万
查看次数

斯威夫特3; 范围'越界'

我刚刚将Xcode更新到8.0 beta 2和swift 3.0.从swift 2.3更新后,我遇到了很多错误.

我有一个String-extension,它将"self"-string中的Range转换为NSRange:

extension String {

    func NSRangeFromRange(_ range : Range<String.Index>) -> NSRange {

        let utf16view = self.utf16
        let from = String.UTF16View.Index(range.lowerBound, within: utf16view)
        let to = String.UTF16View.Index(range.upperBound, within: utf16view)

        print("to: \(to) from: \(from)")
        print(self.characters.count)

        return NSMakeRange(utf16view.startIndex.distance(to: from), from.distance(to: to))
    //    return NSMakeRange(0, 0)    // <-- removes exception
    }
}
Run Code Online (Sandbox Code Playgroud)

当执行NSMakeRange时,我收到一个错误:

因未捕获的异常'NSRangeException'而终止应用程序,原因:'NSMutableRLEArray objectAtIndex:effectiveRange :: out of bounds'

当我打印到索引和索引时,我得到:

to:Index(_offset:194)from:Index(_offset:181)

字符串的字符数210似乎是正确的.

所以,我不明白为什么它告诉我索引是超出界限的,当它们少于总数.

在我更新到swift 3之前,这条线路工作正常.当时它看起来像这样:

return NSMakeRange(utf16view.startIndex.distanceTo(from), from.distanceTo(to))
Run Code Online (Sandbox Code Playgroud)

自动转换器没有将语法从swift 2.3更新到3.0,我自己做了..

有线索吗?

string nsrange swift swift3

4
推荐指数
1
解决办法
3719
查看次数

从 Firebase 可调用函数接收返回的数据

我在 iOS 中使用 Callable HTTPS 功能。我已经创建并部署了以下功能:

export const generateLoginToken = functions.https.onCall((data, context) => {

    const uid = data.user_id
    if (!(typeof uid === 'string') || uid.length === 0) {
        throw new functions.https.HttpsError('invalid-argument', 'The function must be called with one argument "user_id" ');
    }

    admin.auth().createCustomToken(uid)
    .then((token) => {
        console.log("Did create custom token:", token)
        return { text: "some_data" };
    }).catch((error) => {
        console.log("Error creating custom token:", error)
        throw new functions.https.HttpsError('internal', 'createCustomToken(uid) has failed for some reason')
    })
})
Run Code Online (Sandbox Code Playgroud)

然后我从我的 iOS 应用程序调用该函数,如下所示:

let callParameters …
Run Code Online (Sandbox Code Playgroud)

ios firebase swift google-cloud-functions

4
推荐指数
1
解决办法
2677
查看次数

Cocoapods正在安装旧的Pod版本

RxSwift根据Podfile.lock我的使用RxSwift (3.2.0),我在我的应用程序中使用和其他Rx-pods ,但现在我想将Pod 更新到最新版本.

所以我删除了我使用的4个Rx ..- pod Podfile,然后运行pod install,这从项目中移除了pod Podfile.lock.我重新添加4个Rx ..- pod并pod instal重新运行.这安装RxSwift 2.6.1...... 为什么?- 我期待它安装最新的稳定版本RxSwift,如3.6.1 ..

我尝试删除列出的所有内容:gem list --local | grep cocoapods并通过运行重新安装cocoapods:gem install cocoapods

我也尝试过pod repo update没有成功的运行.

我也尝试过只运行pod update,而不首先卸载Pod,也是同样的结果.

我怀疑这是我的cocoapods-gem的一个问题,而不是The Rx-pods ..

编辑添加Podfile:

source 'https://github.com/CocoaPods/Specs.git'
# Uncomment this line to define a global platform for your project
platform :ios, '9.0'
# …
Run Code Online (Sandbox Code Playgroud)

terminal ios cocoapods swift

3
推荐指数
1
解决办法
3135
查看次数

获取 Fastfile 中的车道名称

我正在设置Fastfilefor fastlane,并且正在尝试打开 fastlane 正在运行的车道名称。

说我跑fastlane wow

在此Fastfile,我想获取当前调用的车道的名称fastlane,即"wow"

wowness = (lane[:lane-name] == "wow" ? "Much wow" : "Not so wow")
puts wowness

lane :wow do |options|
    puts "print something random"
end
Run Code Online (Sandbox Code Playgroud)

据我了解fastlaneRuby 的用途,所以也许这可能是要走的路?

ruby fastlane

3
推荐指数
1
解决办法
2044
查看次数

从 UICollectionView 索引路径获取模型

我正在使用RxSwift将模型数组绑定到集合视图

如何从给定的 indexPath 获取模型对象?

我正在做这样的绑定:

vm.bikeIssueCatagories()
        .drive(self.collectionView.rx.items(cellIdentifier: "BikeIssueCategoryCollectionViewCell", cellType: UICollectionViewCell.self)) { row, data, cell in
        }.disposed(by: disposeBag)
Run Code Online (Sandbox Code Playgroud)

我的问题的核心是,我需要获取用户选择的模型对象和单元格。Using collectionView.rx.modelSelected(T.self)only 给了我模型 og type T。打电话collectionView.rx.itemSelected只给我选择的IndexPath

collectionView.rx.itemSelected.asDriver()
        .driveNext { [unowned self] indexPath in
            guard let model = try? collectionView.rx.model(at: indexPath) else { return }
            guard let cell = self.collectionView.cellForItem(at: indexPath) else { return }
        }.disposed(by: disposeBag)
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试在 indexPath 处创建模型时,这给了我一个错误:

类型“inout UICollectionView”不符合协议“ReactiveCompatible”

试试看:

let indexPath = IndexPath.init()
self.collectionView.rx.model(at: indexPath)
Run Code Online (Sandbox Code Playgroud)

也给了我一个错误:

对成员“model(at:)”的不明确引用

SO...如何获取用户选择的模型对象和单元格?

ios swift rx-swift rx-cocoa

3
推荐指数
1
解决办法
2246
查看次数

将 accessToken 存储在 iOS 钥匙串中

我正在寻找在 iOS 钥匙串中存储/​​加载accessToken 和refreshToken 的简单方法。

到目前为止我已经做到了:

    enum Key: String {
        case accessToken = "some.keys.accessToken"
        case refreshToken = "some.keys.refreshToken"
    
        fileprivate var tag: Data {
            rawValue.data(using: .utf8)!
        }
    }

    enum KeychainError: Error {
        case storeFailed
        case loadFailed
    }
    
    func store(key: Key, value: String) throws {
        let addQuery: [String: Any] = [
            kSecClass as String: kSecClassKey,
            kSecAttrApplicationTag as String: key.tag,
            kSecValueRef as String: value
        ]
        let status = SecItemAdd(addQuery as CFDictionary, nil)
        guard status == errSecSuccess else {
            print("Store key: '\(key.rawValue)' in Keychain …
Run Code Online (Sandbox Code Playgroud)

keychain ios swift

2
推荐指数
1
解决办法
5041
查看次数