小编iel*_*ani的帖子

如何设置AFNetworking 2.0默认标头?

以下命令适用于AFNetworking 1.x库

[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
...
[self setDefaultHeader:@"Accept" value:@"application/json"];
Run Code Online (Sandbox Code Playgroud)

AFNetworking 2.0中这些功能的等价物是什么?

谢谢

objective-c ios afnetworking afnetworking-2

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

如何在Swift中按下按钮时防止uibutton alpha变为零?

UI按钮的alpha值变为零,点击时变为透明.我添加了这个IBAction

@IBAction func btnTapped(sender: UIButton) {
    sender.highlighted = false
    //...
}
Run Code Online (Sandbox Code Playgroud)

触摸时UIButton仍然变得透明.怎么预防?

uibutton ios swift

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

是否可以使用Swift旋转IBDesignable UIButton?

如何制作具有角度的IBDesignable组件:旋转视图的CGFloat属性

import UIKit

@IBDesignable
class MyB: UIButton {
    @IBInspectable
    var angle: CGFloat = 0 {
        didSet {
            //What to put here?
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        // Initialization code
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}
Run Code Online (Sandbox Code Playgroud)

我试过了

self.transform = CGAffineTransformMakeRotation(angle)
Run Code Online (Sandbox Code Playgroud)

但它不起作用

swift

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

如何在 Swift 中的 UI 选项卡栏上应用渐变?

我通过故事板构建了选项卡栏,并自定义颜色,我在应用程序委托中更改它,使用UITabBar.appearance().barTintColor = Color

我有一个梯度方法是这样的:

func setGradientBackground(colorOne: UIColor, colorTwo: UIColor)  {
    let gradientlayer = CAGradientLayer()
    gradientlayer.frame = bounds
    gradientlayer.colors = [colorOne.cgColor, colorTwo.cgColor]
    gradientlayer.locations = [0, 1]
    gradientlayer.startPoint = CGPoint(x: 1.0, y: 0.0)
    gradientlayer.endPoint = CGPoint(x: 0.0, y: 0.0)

    layer.insertSublayer(gradientlayer, at: 0)

}
Run Code Online (Sandbox Code Playgroud)

如何将其应用到标签栏的背景?

uitabbar ios swift

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

如何在扩展中使用Swift返回Int中的变异函数?

为什么这段代码不起作用?

protocol ExampleProtocol {
    var simpleDescription: String { get }
    mutating func adjust()
}
extension Int: ExampleProtocol {
    var simpleDescription: String {
    return "The number \(self)"
    }
    mutating func adjust() {
        self += 42
    }
}
var x:Int = 7
let y:Int = x.adjust()
Run Code Online (Sandbox Code Playgroud)

这是我在XCODE上得到的

在此输入图像描述

有没有办法让adjust()返回Int而不改变协议中的定义?

swift

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

使用 Swift 使 SKScene 填满整个屏幕

我有以下内容 GameViewController.swift

class GameViewController: UIViewController {

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        println(self.view.frame.size)
        var skView:SKView = self.view as SKView
        if skView.scene == nil {
            skView.showsFPS = false
            skView.showsNodeCount = false

            // Create and configure the scene.
            var scene : SKScene = GameScene(size: skView.bounds.size)
            scene.scaleMode = SKSceneScaleMode.AspectFill

            // Present the scene.
            skView.presentScene(scene)
        }
    }

    override func prefersStatusBarHidden() -> Bool {
        return true
    }
}
Run Code Online (Sandbox Code Playgroud)

它打印:

(320.0,480.0)
Run Code Online (Sandbox Code Playgroud)

如何使GameScene整个屏幕充满而不是在屏幕的顶部和底部留下黑带?

代码在 GameScene.swift

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        /* Setup …
Run Code Online (Sandbox Code Playgroud)

ios sprite-kit skscene swift

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

为Swift 3和Xcode 8构建领域

我按照这里给出的步骤来构建要在iOS项目中使用的领域,我正在使用Xcode 8 beta 3:

我收到这些警告:

ld: warning: ignoring file .../Realm.framework/Realm, missing required architecture x86_64 in file .../Realm.framework/Realm (2 slices)
ld: warning: ignoring file .../RealmSwift.framework/RealmSwift, missing required architecture x86_64 in file .../RealmSwift.framework/RealmSwift (2 slices)
Run Code Online (Sandbox Code Playgroud)

而这个错误

Lipo: -remove's specified would result in an empty fat file
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

realm swift

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

在Swift中是否存在容量大于u_long/UInt64的数字类型?

在Swift中是否存在比u_longUInt64更大容量的类型?

我有一个函数,需要非常大的整数来识别28位数的信用卡号码:

func myFunc(number : /*What to put here?*/) {
    //body
}
Run Code Online (Sandbox Code Playgroud)

什么类型合适?应该将数字视为字符串吗?

swift

4
推荐指数
2
解决办法
1383
查看次数

通配符模式匹配:

通配符模式匹配:如果给定字符串和含有通配符,即一个图案*?,其中?可以匹配到任何单个字符在输入字符串并*可以匹配到任何数量的字符,包括零个字符的,设计一个有效的算法来发现如果与图案匹配完整的输入字符串与否。

例如:

  • 输入:字符串=“xyxzzxy”,模式=“x***y”

    输出:匹配

  • 输入:字符串=“xyxzzxy”,模式=“x***x”

    输出:不匹配

  • 输入:字符串=“xyxzzxy”,模式=“x***x?”

    输出:匹配

  • 输入:字符串=“xyxzzxy”,模式=“*”

    输出:匹配

xcode swift

4
推荐指数
2
解决办法
1605
查看次数

无法在AFNetworking 2中使用自签名证书

我把Apache Server使用的.cer证书放在Xcode项目中.当应用程序尝试与服务器通信时,我在Xcode中收到此错误:

Assertion failure in id AFPublicKeyForCertificate(NSData *__strong)(),
/Users/../ProjectName/AFNetworking/AFSecurityPolicy.m:52
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'Invalid parameter not satisfying: allowedCertificate'
Run Code Online (Sandbox Code Playgroud)

以下是调用服务器的代码:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[self setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModePublicKey]];
[manager POST:@"https://www.example.com/" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
//success
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//failure
}];
Run Code Online (Sandbox Code Playgroud)

我没有运气将固定模式更改为AFSSLPinningModeCertificate.

当我删除这一行:

[self setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModePublicKey]];
Run Code Online (Sandbox Code Playgroud)

服务器响应错误消息:

"The operation couldn't be completed. (NSURLErrorDomain error -1012.)"
Run Code Online (Sandbox Code Playgroud)

证书是使用OpenSSL创建的,我甚至尝试过StartSSL.com的免费证书

至于Apache Server端,这里是虚拟主机配置:

# My custom host
<VirtualHost *:443>
    ServerName www.example.com
    DocumentRoot "/path/to/folder" …
Run Code Online (Sandbox Code Playgroud)

apache ssl-certificate ios afnetworking-2

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