小编Dog*_*fee的帖子

如何在Swift 2.0中使用stringByAddingPercentEncodingWithAllowedCharacters()作为URL

我在Swift 1.2中使用它

let urlwithPercentEscapes = myurlstring.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
Run Code Online (Sandbox Code Playgroud)

现在这给了我一个警告,要求我使用

stringByAddingPercentEncodingWithAllowedCharacters
Run Code Online (Sandbox Code Playgroud)

我需要使用NSCharacterSet作为参数,但是有很多,我无法确定哪个会给我与之前使用的方法相同的结果.

我想要使​​用的示例URL将是这样的

http://www.mapquestapi.com/geocoding/v1/batch?key=YOUR_KEY_HERE&callback=renderBatch&location=Pottsville,PA&location=Red Lion&location=19036&location=1090 N Charlotte St, Lancaster, PA
Run Code Online (Sandbox Code Playgroud)

用于编码的URL字符集似乎包含修剪我的URL的设置.即

URL的路径组件是紧跟主机组件(如果存在)的组件.它在查询或片段组件开始的任何地方结束.例如,在URL http://www.example.com/index.php?key1=value1中,路径组件是/index.php.

但是我不想削减它的任何方面.当我使用我的String时,例如myurlstring它会失败.

但是当使用以下内容时,则没有问题.它用一些魔法编码了字符串,我可以得到我的URL数据.

let urlwithPercentEscapes = myurlstring.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
Run Code Online (Sandbox Code Playgroud)

就这样

使用给定的编码返回String的表示形式,以确定将String转换为合法URL字符串所需的转义百分比

谢谢

string nscharacterset swift swift2

63
推荐指数
3
解决办法
6万
查看次数

模态视图导航栏的位置 - iOS7

在导航控制器中,您可以按预期自动获得导航栏的正确颜色和位置.

像这样

在此输入图像描述

但在模态视图中,当您在导航栏中拖动时,您可以将其放置在顶部,这太靠近载体/电池信息.

在此输入图像描述

所以你可以将它向下拖动,猜测它与自动创建的位置匹配的距离,但是你有一个颜色差异.我试过更改IB中的状态栏设置,没有什么区别.

在此输入图像描述

是否有正确的方法来克服这个问题,例如使模态视图看起来像自动生成的导航视图.

谢谢

position modal-dialog view navigationbar ios7

39
推荐指数
3
解决办法
2万
查看次数

在Swift 2.0中使用Stride

我正试图弄清楚如何在Swift中使用Stride功能.

从Xcode 7.0 beta 6开始,它似乎再次发生了变化.

以前我可以使用

let strideAmount = stride(from: 0, to: items.count, by: splitSize)
let sets = strideAmount.map({ clients[$0..<advance($0, splitSize, items.count)] })
Run Code Online (Sandbox Code Playgroud)

现在,尽管代码提示我无法弄清楚如何使用此功能.

任何例子都会有所帮助,谢谢.

我看过一些例子,但我无法掌握如何使用它.我从Apple Docs获得的所有内容都是有限的.

谢谢

sequence stride swift

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

解析Unpin不会从本地数据存储中删除对象

这应该工作.

这是尝试解决这个问题的众多尝试之一

            myTrainingSessions[indexPath.row].unpinInBackgroundWithBlock{ (succ, e) -> Void in
            if succ == true {

                // just remove from table view etc
                self.myTrainingSessions[indexPath.row].deleteEventually()
                self.myTrainingSessions.removeAtIndex(indexPath.row)
                self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

                // Shows that my object is still in datastore!
                // object should be UNPINNED - but appers in this result....
                var query = PFQuery(className:TrainingSession.parseClassName())
                query.whereKey(self.userType(), equalTo: PFUser.currentUser())
                query.orderByDescending("createdAt")
                query.fromLocalDatastore().ignoreACLs()
                query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
                    if error != nil { return }
                    if let result = objects as? [TrainingSession] {
                        println("local results")
                        println(result)
                    } …
Run Code Online (Sandbox Code Playgroud)

ios parse-platform

20
推荐指数
1
解决办法
3545
查看次数

MapKit iOS 9 detailCalloutAccessoryView用法

在观看WWDC视频206后,我认为将详细的标注视图添加到mapView注释视图是一项微不足道的任务.

所以,我认为我做错了什么.

设置了引脚视图

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    let view:MKAnnotationView!

    if let dequed = routeMapView.dequeueReusableAnnotationViewWithIdentifier("pin") {
        view = dequed
    }
    else {
        view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "pin")
    }

    let x = UIView(frame: CGRectMake(0, 0, 200, 200))
    x.backgroundColor = UIColor.redColor()

    // shows the red
    //view.leftCalloutAccessoryView = x

    // working as no subtitle - but no red view
    view.detailCalloutAccessoryView = x

    view.canShowCallout = true
    return view
}
Run Code Online (Sandbox Code Playgroud)

我只能得到这个

在此输入图像描述

我知道这个观点正在发挥作用,因为如果我试着用它leftCalloutAccessoryView来做 在此输入图像描述

我肯定错过了什么.请注意,如果我只是添加图像detailCalloutAccessoryView

view.detailCalloutAccessoryView …
Run Code Online (Sandbox Code Playgroud)

mapkit mkannotationview ios

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

设备离线时CKQueryOperation不返回错误

我正在尝试使用CKQueryOperation,而不是performQuery在我的CloudKit数据库上.

两者都有效,但是当使用CKQueryOperation时,我在设备离线时没有收到错误,但是在使用时我没有收到错误 performQuery

这是我的performQuery例子,数据库是我的CKDatabase

database.performQuery(q, inZoneWithID: nil) { (records:[CKRecord]?, error:NSError?) in
    if error != nil {
        print(error!.localizedDescription)
        return
    }
}
Run Code Online (Sandbox Code Playgroud)

设备离线时会出现错误,允许我提示用户.错误是

The internet connection appears to be offline

但是,当我使用a时,我没有错误 CKQueryOperation

let p = NSPredicate(format:"recordID IN %@", student.courses)
let q = CKQuery(recordType: String(Course), predicate: p)

let queryOperation = CKQueryOperation(query: q)

queryOperation.recordFetchedBlock = { record in
    // not called without network connection - doesn't enter scope
    print(record)
}


queryOperation.queryCompletionBlock = { (cursor: CKQueryCursor?, error: NSError?) …
Run Code Online (Sandbox Code Playgroud)

ios cloudkit

14
推荐指数
1
解决办法
388
查看次数

SpriteKit - 设置比例和物理

在场景中"缩小"的正确方法是什么?

我有一个对象,我施加冲动在屏幕上触发它.例如,它将在大约100 px的范围内射击.这可以按预期工作 - 增加飞行的力量,增加飞行的密度等.

我的问题是缩放,我知道缩小场景的唯一方法是setScale,并按预期缩小我的所有节点.

但是,然后飞行相同数量的物体(刚刚缩小)而不是飞行距离的两倍以上.

当我在比例之前和之后记录对象的质量/密度等时,它们是相同的,如预期的那样.

那么为什么它的飞行量不一样呢?尝试改变冲动以匹配比例,但它不起作用,是的它飞行距离较少 - 但它不是一个与缩放的一个.

棘手的问题......

谢谢你的想法.

physics sprite-kit

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

应用角度冲动

嗨,大家好,我的代码是玩家和互相交互的球.我想做的是对球施加力,就像我的球员正在射击它一样.我希望球能够用力从球员身上移开.我怎样才能对此施加Impulse或force.我尝试了很多次,但我是Sprite Kit的新手.

- (void) Player {
    _Player = [SKSpriteNode spriteNodeWithImageNamed:@"player1"];
    _Player.xScale = 0.09;
    _Player.yScale = 0.09;
    _Player.position = CGPointMake(self.size.width/4, self.size.height/2);
    _Player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_Player.size];
    _Player.physicsBody.dynamic = NO;
    [self addChild:_Player];
}

- (void) TheMethodForBall {
    SKSpriteNode *sprites = [SKSpriteNode spriteNodeWithImageNamed:@"ball"];
    sprites.xScale = 0.19;
    sprites.yScale = 0.19;
    sprites.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:sprites.size];
    sprites.physicsBody.dynamic = YES;
    sprites.physicsBody.affectedByGravity = NO;
    sprites.physicsBody.allowsRotation = YES;
    sprites.physicsBody.restitution = YES;
    sprites.physicsBody.angularVelocity = 4;
    sprites.physicsBody.usesPreciseCollisionDetection = YES;
    [self addChild:sprites];
}
Run Code Online (Sandbox Code Playgroud)

physics sprite-kit

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

Sprite Kit iOS7 - SKNode UserData属性不存储值

我认为这项工作很容易,但我无法理解为什么我的NSMutableDictionary属性不能像我预期的那样工作.

[self.testSprite.userData setValue:@"CAT" forKey:@"key"];
NSLog(@"%@", [self.testSprite.userData objectForKey:@"key"]);
NSLog(@"%lu", [self.testSprite.userData count]);
Run Code Online (Sandbox Code Playgroud)

我重新调整(null)和0.

有没有使用spriteNode userdata的特殊技巧?

谢谢

sprite nsmutablearray user-data sprite-kit

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

Sprite Kit iOS7 - 添加滑块

我以为你可以在精灵套件应用程序中添加UIKit滑块/或按钮.

但无法弄清楚如何做到这一点,以编程方式创建滑块的代码是

if (self.view) {
    CGRect frame = CGRectMake(0.0, 0.0, 200.0, 300);
    UISlider *slider = [[UISlider alloc] initWithFrame:frame];
    //[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    [slider setBackgroundColor:[UIColor clearColor]];
    slider.minimumValue = 0.0;
    slider.maximumValue = 50.0;
    slider.continuous = YES;
    [self.view addSubview:slider];
    NSLog(@"View is alive - look for slider...");
} 
else {
    NSLog(@"No View!!");
}
Run Code Online (Sandbox Code Playgroud)

以上不起作用,视图的子视图数量保持不变

我假设我必须将它作为子项添加到我的图层(SKNode),但addChild方法不适用于UISlider.它需要是一个SKNode本身.

我在这里的场景课中叫这个

-(id)initWithSize:(CGSize)size {    

    if (self = [super initWithSize:size]) {
         // thought putting here would work 
         // but self.view is nil
    }

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

感谢评论,我可以让它显示 - 但我必须在viewController类中添加,就像这样 …

uislider sprite-kit

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