小编tod*_*ddg的帖子

受密码保护的 UITextField 上的大写锁定图像

我正在创建一个需要使用 USB 键盘的应用程序。(普通触摸屏键盘已被禁用,不会显示。)当用户第一次安装应用程序时,他们需要创建一个四位数的 Pin。Pin 的输入字段受密码保护(因为每次输入新数字时都会出现点)。Pin UITextField 设置为仅四位数字除外。任何其他字母/数字都不会添加到 UITextField。这是它的样子——

链接到图像。

这里的问题是当用户单击 USB 键盘上的大写锁定按钮时,大写锁定图像将出现在 UITextField 中。但是,该字段只接受数字,所以我不想在文本字段中显示大写锁定图像。有没有办法删除大写锁定图像?

password-protection capslock uitextfield ios swift

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

ios swift 核心图形 - 字符串颠倒

当我想在 CGContext 中绘制字符串时,文本出现颠倒。

我知道这个主题已经发布在这里,但没有一个解决方案对我有用。

我确实翻转了上下文:

graphContext.scaleBy(x: 1.0, y: -1.0)
graphContext.translateBy(
        x: CGFloat(0.0),
        y: CGFloat(-1.0 * graphSize.h))
Run Code Online (Sandbox Code Playgroud)

我也尝试对 textMatrix 执行相同的操作,但这对结果没有任何影响。

完整的项目源在这里:dropbox 屏幕截图在这里:屏幕截图

不明白为什么它不起作用。

谢谢

我的绘制方法:

override func draw(_ rect: CGRect) {

        let graphSize = GSize(
            w: Double(self.frame.width),
            h: Double(self.frame.height))

        rebaseAreas(graphSize: graphSize)

        graphContext = UIGraphicsGetCurrentContext()!
        graphContext.saveGState()

        // Flip the context coordinates, in iOS only
        graphContext.scaleBy(x: 1.0, y: -1.0)
        graphContext.translateBy(
            x: CGFloat(0.0),
            y: CGFloat(-1.0 * graphSize.h))


        // this has no effect, I can delete it and nothing changes
        graphContext.textMatrix = CGAffineTransform(scaleX: …
Run Code Online (Sandbox Code Playgroud)

string core-graphics ios swift

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

Why am I unable to install a constraint on my view?

I am trying to animate a button from outside the visible bounds of my UIViewController to the center of it. I have a constraint setup in my storyboard called myButtonLeading which I remove as part of my animation, and then I want to add a new constraint called newCenterConstraint.

@IBAction func updateDidTouch(_ sender: Any) {

    UIView.animate(withDuration: 0.5, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: {

        let newCenterConstraint = NSLayoutConstraint(item: self.myButton, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1.0, constant: …
Run Code Online (Sandbox Code Playgroud)

uiviewanimation ios nslayoutconstraint swift

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

解析JavaScript SDK并保证链接

我在Parse Cloud Code中创建了一个后台作业,它根据我的一个Parse类中的日期发送电子邮件通知.

这是一个想法:查询包含日期的类.迭代返回的每个对象并检查日期字段.如果日期等于今天,请发送电子邮件通知,将日期更改为null并将其保存回Parse.

但是,似乎并非所有对象都保存回Parse.我怀疑这是我的承诺链的问题,但我很难诊断确切的问题或如何解决它.以下是相关代码

Parse.Cloud.job("job", function(request, status) {


// Query for all users
var query = new Parse.Query(className);
query.each(function(object) {

    if (condition) {

        object.set(key, false);
        object.save(null, {
            success:function(object){
                // This never executes!
            },
            error: function(error){

            }

        }).then(function(){
            // This never executes
            console.log("Save objects successful");
        },
        function(error){
            status.error("Uh oh, something went wrong saving object");
        });

        // Set hiatus end successful
        Mailgun.sendEmail({
        });
    }

    });
});
Run Code Online (Sandbox Code Playgroud)

console.log("Save objects successful");即使订阅对象成功保存到Parse,object.save()promise链中的这一行也不会被执行.

此外,如果查询返回的对象超过5个,则只有前5个成功保存回Parse.不执行任何其他保存,也不会发送电子邮件通知.

javascript promise parse-platform parse-cloud-code

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

如何使用Swift在iOS开发中实现"缓存"

我在面向iOS应用程序实现的缓存机制方面遇到了一些问题.首先,让我解释一下我的情况.

我想通过我的服务器上的RESTful API使用Alamofire请求数千个附近的位置记录(10000或更多),其中每个记录由一串字符串组成.JSON响应格式与此类似:

[
   {
     "id": 1,
     "name": "Name x",
     "lat": 59.5025878,
     "lng": -0.1509515,
     "address": "Address x"
   },
   {
     "id": 2,
     "name": "Name y",
     "lat": 61.5025878,
     "lng": -0.1508515,
     "address": "Address y"
   },

   etc.

 ]
Run Code Online (Sandbox Code Playgroud)

关键是我只想在应用程序启动时或经过一定时间后或应用程序用户大幅移动他/她的位置时发送/重新发送此查询,这也会改变附近的位置.为了保持服务器负载较低,我计划对应用程序内部的返回位置进行搜索查询,而不是为每个请求查询服务器,这实际上是低效且昂贵的.

因此,我想在手机上缓存我的响应数据,但我不知道选择哪个选项.我在CoreDataNSCache上做了一些背景阅读.CoreData允许我将位置结果存储在数据库中.这样做的好处是存储的记录在内部保持活跃,因为它毕竟是永久存储解决方案.另一方面,使用CoreData可能是一个完全的过度杀伤,因为它带来了开销,使用NSCache将位置记录保存在缓存中可能不会占用太多内存(记住我只存储字符串).但话说回来,为什么当用户甚至不经常访问它们时,将位置数据保留在缓存中.此外,有可能释放缓存中的位置条目以节省更多内存.

我相信还有其他解决方案可能更适合我的目的.毕竟,我对iOS中的这个主题很新,所以我真的很感激一些指导.

先感谢您.

caching core-data ios nscache swift3

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

迅捷3-WKWebView中的HTTP身份验证

我正在尝试构建一个显示网页的简单WebView-该页面要求所有页面都使用http身份验证(出于测试目的)。

这是我的代码:

class ViewController: UIViewController, WKUIDelegate {

    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }

    // #1 variant
    func webView(webView: WKWebView, willSendRequestForAuthenticationChallenge challenge:
        URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        let user = "user"
        let password = "pass"
        let credential = URLCredential(user: user, password: password, persistence: URLCredential.Persistence.forSession)
        challenge.sender?.use(credential, for: challenge)
    }

    // #2 variant
    func webView(webView: WKWebView, didReceiveAuthenticationChallenge challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> …
Run Code Online (Sandbox Code Playgroud)

http-authentication swift wkwebview swift3

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

无法读取未定义的属性'textContent'

我正在尝试创建一个动画徽标灵感:http://codepen.io/pavlunya/pen/OPmVem

当我使用document.getElementById而不是时,我收到错误document.getElementsByTagName

的jsfiddle

在此先感谢您的帮助

javascript

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

通用链接会访问我的服务器吗?

我已经使用后端的别名子域和类似方案在我的 iOS 应用程序上设置了通用链接sudomain.mydomain.com. 我希望未安装该应用程序的用户能够重定向到我们在 App Store 中的页面,而不是访问我们服务器上一些不存在的端点(我们没有 Web 应用程序,只有移动后端)。

我正在考虑做这样的事情:

app.get('*', (request, response) => {

    const domain = request.headers.host,
      subdomain = domain.split('.');

    if ( subdomain[0] === 'subdomain'){
        response.redirect('www.linktoappstore.com');   
    } 
    ...
});
Run Code Online (Sandbox Code Playgroud)

但是,我不希望这干扰确实安装了该应用程序的人的通用链接。通用链接get请求是发送到我的服务器还是 iOS 会在此之前拦截它们?

node.js ios express ios-universal-links

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

可可错误3840仅解析代码iOS7

背景:几天前我决定从Facebook-iOS-SDK v3.24将Facebook SDK更新为FBSDKCoreKit.我相应地更新了我的Podfile并安装了所有库.然后我开始更新一些代码以使用更新的SDK规范.

经过一段时间的努力后,我改变主意,决定回滚到旧版本.我做了所有必要的cocoapods更改和安装,丢弃了Xcode中的所有本地更改,重新编译并运行.一切都很好......或者我认为.

问题:现在,当我尝试在我的旧iOS7测试设备上运行时,每当应用程序启动时我都会收到错误消息.以下是确切的控制台输出:

2015-10-15 20:14:31.271 hiatus[184:6003] [Error]: Failed to run command eventually with 
error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be
completed. (Cocoa error 3840.)" (JSON text did not start with array or object
and option to allow fragments not set.) UserInfo=0x14d67d20 {NSDebugDescription=
JSON text did not start with array or object and option to allow fragments not set.}
Run Code Online (Sandbox Code Playgroud)

在控制台中显示此错误后,没有Parse功能可用.在我的情况下,这意味着用户无法登录.而是显示空错误.

在iOS8和iOS9(模拟器和真实设备)上一切正常.我正在使用Parse v1.9.我试过清理项目,重置等,但没有任何成功.

我已经能够将其跟踪到PFEventuallyQueue.m中的特定功能.它似乎发生在(void)_runCommandsWithRetriesCount:.我只是无法知道如何解决它.

cocoa objective-c facebook-ios-sdk cocoapods parse-platform

0
推荐指数
1
解决办法
737
查看次数

iOS swift如何在需要返回值的函数内等待异步任务

我正在使用swift 3.0并创建了一个返回整数数组的函数.整数数组非常具体,它们来自数据库,因此HTTP调用是异步的.这是一个功能,因为我在3个不同的控制器中使用它,所以写一次是有意义的.我的问题是在底部的return语句之后返回异步代码,因此返回nil.我在这里试过这个例子等待任务完成但是它不起作用主要是因为我需要返回值.这是我的代码

func ColorSwitch(label: [UILabel]) -> [Int] {

    for (index, _) in label.enumerated() {
       label[index].isHidden = true
    }

    // I need the value of this variable in the return
    // statement after the async is done
    var placeArea_id = [Int]()

    let urll:URL = URL(string:ConnectionString+"url")!

    let sessionn = URLSession.shared
    var requestt = URLRequest(url: urll)
    requestt.httpMethod = "POST"


    let group = DispatchGroup()
    group.enter()

    let parameterr = "http parameters"
    requestt.httpBody = parameterr.data(using: String.Encoding.utf8)
    let task =   sessionn.dataTask(with:requestt, completionHandler: {(data, response, error) …
Run Code Online (Sandbox Code Playgroud)

asynchronous ios swift nsurlsessiondatatask swift3

0
推荐指数
1
解决办法
3744
查看次数