小编Viv*_*ive的帖子

位置坐标无效

我有两个坐标:

@property (assign) CLLocationCoordinate2D coordinate1;
@property (assign) CLLocationCoordinate2D coordinate2;
Run Code Online (Sandbox Code Playgroud)

在初始化期间,我将它们设置为无效(以后能够检查它是否已设置):

_coordinate1 = kCLLocationCoordinate2DInvalid;
_coordinate2 = kCLLocationCoordinate2DInvalid;
Run Code Online (Sandbox Code Playgroud)

然后在方法中检查它们是否有效:

- (void)checkIfValid {
    BOOL coordinatesAreValid = (CLLocationCoordinate2DIsValid(_coordinate1) && CLLocationCoordinate2DIsValid(_coordinate2));
    NSAssert(coordinatesAreValid, @"You didn't set up coordinates!");
}
Run Code Online (Sandbox Code Playgroud)

在我调用方法之前,我通过这种方式设置这些坐标:

[_myclassinstance setCoordinate1:CLLocationCoordinate2DMake(mapView.region.center.longitude, mapView.region.center.latitude)];
[_myclassinstance setCoordinate2:CLLocationCoordinate2DMake(mapView.region.center.longitude, mapView.region.center.latitude)];
[_myclassinstance checkIfValid];
Run Code Online (Sandbox Code Playgroud)

问题是应用声称,坐标是错误的.我打印过它们,它们似乎没问题:

(lldb) p _coordinate1
(CLLocationCoordinate2D) $1 = {
  latitude = -122.4612387012154
  longitude = 37.72925050874177
}
(lldb) p _coordinate2
(CLLocationCoordinate2D) $2 = {
  latitude = -122.3582012987846
  longitude = 37.84612098703619
}
Run Code Online (Sandbox Code Playgroud)

但是打印检查不起作用,也断言运行:

p (int)CLLocationCoordinate2DIsValid(_coordinate1)
(int) $3 = 0
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么会这样?欢迎任何帮助:)

objective-c core-location ios

4
推荐指数
1
解决办法
2356
查看次数

制图将约束设置为变量

我不知道如何将constrant.height设置为常量值:

override func updateConstraints() {
    layout(view) { view in
        let viewHeight = 67

        view.top == view.superview!.top
        view.left == view.superview!.left
        view.height == viewHeight // Error: Binary operator '==' cannot be applied to operands of type 'Dimension' and 'Int'
        view.width == view.superview!.width
    }

    super.updateConstraints()
}
Run Code Online (Sandbox Code Playgroud)

这应该很简单,作为一个Swift新手atm我没有任何工作的想法,欢迎任何帮助:)

cartography ios swift

4
推荐指数
1
解决办法
695
查看次数

NSArray - >找到最接近的价值 - 最快的方式

让我们说我已经订购NSArrayNSNumbers:

2, 4, 8, 15, 16, 20 // for simplicity let's treat it as array of int's instead of NSNumbers
Run Code Online (Sandbox Code Playgroud)

现在我需要找到最接近的索引来说value == 19.

searchValue = 19;
minIndex = 0;
maxIndex = array.count - 1;
currentIndex = (int)floorf(maxIndex / 2.f);

while (maxIndex - minIndex == 1) {
    if (array[currentIndex] < searchValue) { // go right
        minIndex = currentIndex;
    } else if (array[currentIndex] > searchValue) { // go left
        maxIndex = currentIndex;
    } else { // …
Run Code Online (Sandbox Code Playgroud)

algorithm objective-c

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

Cocoapods(私人)无法找到规格

我们有私人cocoapods.当我输入pod repo:

company-private
- Type: git (origin)
- URL:  ssh://me@myCompany.com//path/git/PrivateCocoapods
- Path: /Users/Username/.cocoapods/repos/company-private

master
- Type: git (origin)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/Username/.cocoapods/repos/master
Run Code Online (Sandbox Code Playgroud)

我进入了~/.cocoapods/repos:

$ ls
company-private  master
$ cd company-private
$ ls
Specs
$ cd Specs:
$ ls
MyProject
$ cd MyProject:
$ ls
0.0.19  0.0.2  0.0.5
$ cd /0.0.5:
$ ls
MyProject.podspec
Run Code Online (Sandbox Code Playgroud)

在另一个项目中.podfile我试图:

pod 'MyProject', '0.0.5'
Run Code Online (Sandbox Code Playgroud)

之后pod installpod update我得到:

$ pod install
Analyzing dependencies
[!] Unable to …
Run Code Online (Sandbox Code Playgroud)

git objective-c ios cocoapods

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

Xcode 6 LaunchScreen.xib错误的iOS7 iPhone 5窗口大小

我在Xcode 6中创建了我的项目,并且我使用的是默认的LaunchScreen.xib文件.在iOS 8中,一切都运行良好,但是当我在iOS 7.0.3上测试时,项目似乎无法使用iPhone 5 - 我的顶部和底部都有黑条.正如我所说,在iPhone 5 iOS 8上一切正常.

当我查看xib文件时:

Size - freeform (changing to inferred doesn't help)
Orientation - inferred
Status bar - none
Top bar - inferred
Bottom bar - inferred
Run Code Online (Sandbox Code Playgroud)

知道怎么解决吗?

- 编辑 -

我通过模式创建了一个新项目(单视图应用程序 - >设备(通用)),仅将项目信息 - > iOS部署目标更改为5.0.当我在iPhone 5s iOS 7.0.3模拟器上运行时,屏幕不会被应用程序填满.这似乎是Apple提出的错误.

iphone xcode xib ios

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

错误:'String'无法转换为'String!'

mapView.rac_valuesForKeyPath("userTrackingMode", observer: self).subscribeNextAs { 
// block handling
Run Code Online (Sandbox Code Playgroud)

我收到一个错误'String' is not convertible to 'String!'.有什么建议可能意味着什么?

我以前认为,这String!是相同的String,所以它是打开的String?...

  • Xcode 7.3.1
  • Swift 2.2
  • ReactiveCocoa 4.1.0

string reactive-cocoa swift

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

Dispatch_async和UI

我发出警报通知用户有关保存操作的信息,我将其添加到查看,保存一些图像并解除警报.然而,它并没有像我希望的那样工作.首先在控制台中查看下面的代码,我得到"保存..."然后"发送".我想得到相反的效果首先得到"dispath"然后"保存.."(所以在屏幕上写警报,然后保存在后台,最后解除警报).但我改变了imageView1的图像,所以我不能移出dispath_async合并,因为它是一个UI动作..然后怎么办呢?我需要首先合并图像并在它之后保存它们以及所有这些计算时间以保持警惕.

//adding alert to view
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), 
^{
    dispatch_async(dispatch_get_main_queue(), ^{
        //i want this to complete->
        imageView1.image = [self merge:imageView1.image and:imageView2.image];
        NSLog(@"dispatch");
    });

    //and then to do this action->
    UIImageWriteToSavedPhotosAlbum(imageView1.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
    NSLog(@"saved..");

    dispatch_async(dispatch_get_main_queue(), ^{
        [alert dismissWithClickedButtonIndex:0 animated:YES];
    });
});
Run Code Online (Sandbox Code Playgroud)

iphone objective-c dispatch

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

在折线/路径中查找最近的点

我需要从给定CLLocationCoordinate2D的数组中找到最近的点GMSPolyline.GMSPath如果那更好的话,我可以将其转换为.是否有任何现成的方法(或任何存储库)进行此类计算?我在实施方面遇到了一些问题.我想知道如何创建一个算法:

1. for all polylines
1.1. find smallest distance between polyline and touch point, save CLLocationCoordinate2D
2. for all distances from point 1.1.
2.1. find the shortest one, it's CLLocationCoordinate2D is our point
Run Code Online (Sandbox Code Playgroud)

现在的问题是如何实现1.1点?

基于SOF最短距离问题,我写了这样的代码:

- (void)findNearestLineSegmentToCoordinate:(CLLocationCoordinate2D)coordinate {
    GMSPolyline *bestPolyline;
    double bestDistance = DBL_MAX;
    CGPoint originPoint = CGPointMake(coordinate.longitude, coordinate.latitude);
    for (GMSPolyline *polyline in self.polylines) {
        polyline.strokeColor = [UIColor redColor]; // TMP

        if (polyline.path.count < 2) { // we need at least 2 …
Run Code Online (Sandbox Code Playgroud)

google-maps objective-c polyline ios

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

NSString修剪不起作用

我有:

NSString *urlString = @"+11 111 111 111";
NSString *trimmedUrlString = [urlString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", trimmedUrlString]];
Run Code Online (Sandbox Code Playgroud)

然而,当我检查他们,trimmedUrlString是同urlStringurlnil.有没有人知道为什么trimmedUrlString没有修剪..?

objective-c ios

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