我正在玩自定义和交互式视图控制器转换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) 我有一个自定义布局的collectionView,到目前为止我只有一个UICollectionReusableView.起初一切正常:
prepareLayout() 被称为填充缓存, collectionViewContentSize() 被调用并返回正确的cententSize和 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() …
我已经为一个领域对象添加了一个值(我已将动态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? …
考虑以下对象:
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) 我是Xcode和iPhone编程的新手.我有一个简单的问题,这让我烦恼..我想在一个按钮上设置一个图像,因为它是默认状态.所以我选择了按钮,在"显示属性检查器"选项卡中,我选择"状态配置"为默认值,然后在"图像" - 下拉列表中找到所需的图像...
问题:
我将"状态配置"更改为选中,图像仍然打开.我需要图像仅在默认状态下打开.如果我想在默认和选择状态下标题文本的字体大小不同,我也有同样的问题.我正在使用Xcode 4.6并为iOS 6.1编写.
我刚刚将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,我自己做了..
有线索吗?
我在 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) 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) 我正在设置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 的用途,所以也许这可能是要走的路?
我正在使用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 钥匙串中存储/加载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)