小编Dev*_*ist的帖子

旋转事件时无法修复自动布局动画

不要害怕这里会有大量的代码.您可以将代码段复制并粘贴到新的单个视图应用程序中,以查看其行为方式.问题位于与旋转动画一起执行的动画完成块内的某处.

import UIKit

let sizeConstant: CGFloat = 60

class ViewController: UIViewController {

    let topView = UIView()
    let backgroundView = UIView()
    let stackView = UIStackView()
    let lLayoutGuide = UILayoutGuide()
    let bLayoutGuide = UILayoutGuide()
    var bottomConstraints = [NSLayoutConstraint]()
    var leftConstraints = [NSLayoutConstraint]()

    var bLayoutHeightConstraint: NSLayoutConstraint!
    var lLayoutWidthConstraint: NSLayoutConstraint!

    override func viewDidLoad() {

        super.viewDidLoad()

        print(UIScreen.main.bounds)

        //        self.view.layer.masksToBounds = true

        let views = [
            UIButton(type: .infoDark),
            UIButton(type: .contactAdd),
            UIButton(type: .detailDisclosure)
        ]
        views.forEach(self.stackView.addArrangedSubview)

        self.backgroundView.backgroundColor = UIColor.red
        self.backgroundView.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(self.backgroundView)

        self.topView.backgroundColor = UIColor.green
        self.topView.translatesAutoresizingMaskIntoConstraints = …
Run Code Online (Sandbox Code Playgroud)

animation ios autolayout swift

15
推荐指数
1
解决办法
905
查看次数

Swift:覆盖子类内的typealias

所以我在考虑项目中的自定义模式,但我无法让它工作.主要的想法是改变typealias每个子类以访问子类特定的接口.

protocol InstanceInterface: class {

    typealias Interface

    var interface: Interface { get }
}

// Baseclass
protocol FirstClassInterface: class { /* nothing here for the example */ }

class FirstClass: InstanceInterface, FirstClassInterface {

    typealias Interface = FirstClassInterface

    var interface: Interface { return self }
}

// Subclass
protocol SecondClassInterface: FirstClassInterface { 

    func foo()
}

class SecondClass: FirstClass, SecondClassInterface {

    typealias Interface = SecondClassInterface // <--- This does nothing :(

    func foo() { print("hello world") } // Swift 2.0 …
Run Code Online (Sandbox Code Playgroud)

generics protocols swift swift2

11
推荐指数
2
解决办法
5865
查看次数

iOS:默认的IB popover转换做的很奇怪

我碰到了一个奇怪的问题,当一个视图控制器出现在一个弹出框中时,呈现视图控制器view不会被捕捉到它的超视图的底边,在这种情况下就是window它自身.

AppDelegate代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    let window = UIWindow(frame: UIScreen.main.bounds)
    window.rootViewController = UIStoryboard(name: "NavigationController", bundle: Bundle.main).instantiateInitialViewController()
    window.makeKeyAndVisible()
    window.backgroundColor = .yellow // Needed to detect the issue.
    self.window = window

    return true
}
Run Code Online (Sandbox Code Playgroud)

要测试的故事板:

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="4lt-Df-IeL">
    <device id="retina5_5" orientation="portrait">
        <adaptation id="fullscreen"/>
    </device>
    <dependencies>
        <deployment identifier="iOS"/>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
        <capability …
Run Code Online (Sandbox Code Playgroud)

rotation storyboard uiviewcontroller ios

10
推荐指数
0
解决办法
323
查看次数

Swift 2.2:无法将'[B]'类型的值转换为指定类型'[A]'

我正式混淆为什么这不起作用(这里没有太多要解释):

protocol A {

    var value: Int { get set }
}

struct B: A {

    var value: Int
}

let array: [B] = [B(value: 10)]

let singleAValue: A = array[0] // extracting works as expected

var protocolArray: [A] = []
protocolArray.append(singleAValue) // we can put the value inside the `protocolArray` without problems
print(protocolArray)

let newProtocolArray: [A] = array // but why does this conversion not work?
Run Code Online (Sandbox Code Playgroud)

arrays casting swift

9
推荐指数
1
解决办法
504
查看次数

CloudKit:免费的公共存储和数据传输

我想了解CloudKit免费使用计算,但我不能.

任何人都可以描述一下40 requests per seconds(每100,000个用户10个)吗?我找不到任何定义请求是什么.如果我有2个应用程序,并且每个应用程序会同时ping我的CloudKit服务器,它会导致每秒两个请求(对于描述的时刻)?我如何知道如何限制我的应用程序中的请求以及如何对请求进行排队,以便以后可以在CloudKit服务器未达到限制的时间完成这些请求?

怎么样2GB data transfer(每用户50 MB)?我应该如何理解这些每周50 mb,每秒,永恒?如果我的某个应用程序的某个用户使用了50 MB的流量,会发生什么?

如何限制我的应用程序并仍然具有良好的clint服务器通信?达到限制时是否会收到错误,Apple不会自动收取费用?

我真的很喜欢编程的简易性,CloudKit但我有点害怕它可能会出错,我会因误解而受到指控.

我很难想象它是如何计算的.

ios cloudkit

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