小编Xav*_*ero的帖子

将CLLocation或CLLocationCoordinate2D转换为CGPoint

我怎么能转换CLLocationCLLocationCoordinate2DCGPoint.我见过

CGPoint point = [mapView convertCoordinate:myCoordinates toPointToView:self.view];
Run Code Online (Sandbox Code Playgroud)

但我不需要mapView在我的情况下使用.我试过谷歌搜索,但没有遇到任何有用的东西.

编辑:我需要将地理坐标转换为iPad的屏幕坐标,如将十进制纬度/经度坐标转换为iPad屏幕坐标.我试图根据转换的坐标值绘制线/路径.

Is there a direct way to do it, or do I need to write an algorithm to do the same.

iphone cllocation cgpoint ios

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

删除现有注释并将新注释添加到mapview中

我正在加载一个带有单个注释的mapview.就像iphone中的"地图应用"一样.我有一个搜索栏,显示引脚位置的地址,如地图所示.现在我决定更改位置地址.我在搜索栏中输入新的地址位置.然后我的mapview必须删除现有的注释并添加新的注释.现在,我正在添加新注释,但我无法删除现有注释.如何删除现有注释?

iphone mkmapview ios

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

如何在Objective C中使用静态变量(BOOL)

我来自C#背景,我很难弄清楚如何在Objective C中使用静态变量(在我的例子中是BOOL).我的问题是:

  1. 我应该在哪里声明我的静态变量.
  2. 如何从另一个类访问(设置其值).
  3. 我是否需要使用extern关键字.

iphone static boolean objective-c extern

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

UIActionSheet需要很长时间才能做出回应

我正在创建一个UIActionSheeton actionSheet:clickedButtonAtIndex委托方法.

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex     
 if(buttonIndex == 1){

        [self.myFirstView removeFromSuperview]; 

        if (!self.mySecondView) {
            [[NSBundle mainBundle] loadNibNamed:@"MySecondView" owner:self options:nil];
        }
        [self.mySecondView setFrame:CGRectMake(0, 0, 320, 480)];

        [[UIApplication sharedApplication].keyWindow addSubview: self.mySecondView];

        UIActionSheet * action = [[UIActionSheet alloc]initWithTitle:@""
                                                            delegate:self
                                                   cancelButtonTitle: nil
                                              destructiveButtonTitle: deleteContacts
                                                   otherButtonTitles: cancel, nil];
        action.tag = 102;
        [action showInView:self.view];
        [action release];

    }
Run Code Online (Sandbox Code Playgroud)

我用UIActionSheet与上面完全相同的方法处理了click事件.

if(actionSheet.tag == 102){

    if(buttonIndex == 0){
        if([[NSBundle mainBundle] loadNibNamed:@"MyThirdView" owner:self options:nil]) { 
            [self.myThirdView setFrame:CGRectMake(0, 0, 320, 480)];
            [[UIApplication sharedApplication].keyWindow addSubview:self.myThirdView];
        }
        [self.mySecondView removeFromSuperview]; 

        [self.doneButton.target …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uiview uiactionsheet ios

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

IOS 6 mapview中缩放级别的无差异行为

我一直在使用以下代码缩放地图视图,以便所有注释将以最佳缩放级别同时显示在视图中.但在IOS 6中,缩放级别似乎存在一些问题.测试几个案例,我发现1.如果联系人在美国,当加载地图时,它会缩放到其他位置.2.英国地区的缩放级别似乎是正确的(据我测试过).3.当我包括来自英国和美国的联系人时,英国的联系人会得到正确的缩放,但美国的联系人不在视线范围内.但轻微滑动将确保所有触点都适合视图并正确缩放.

-(void)zoomToFitMapAnnotations:(MKMapView*)mapViews insideArray:(NSArray*)anAnnotationArray
{ 
if([mapViews.annotations count] == 0) return;

CLLocationCoordinate2D topLeftCoord;
topLeftCoord.latitude = -90;
topLeftCoord.longitude = 180;

CLLocationCoordinate2D bottomRightCoord;
bottomRightCoord.latitude = 90;
bottomRightCoord.longitude = -180;

for(MKPointAnnotation* annotation in anAnnotationArray)
{
    topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
    topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);

    bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
    bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
}

MKCoordinateRegion region;
region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; // Add a little extra …
Run Code Online (Sandbox Code Playgroud)

iphone ios6 ios6-maps

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

如何在单个视图中处理多个分段控件的事件

我的viewcontroller视图中有2个分段控件.如何处理两个分段控制器的点击事件?

iphone uisegmentedcontrol ios

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

UITextField中的Keypressed事件

我有10个文本字段,在每个文本字段中我只能输入一个字符.在每个文本字段中输入字符后,焦点应移至下一个字段.类似地,当我通过按退格键或删除来删除文本字段中的字符时,我需要将焦点转到上一个文本字段.如果我能得到keypressed事件,我可以做到这一点.现在我无法找到任何按键事件示例.

iphone uitextfield ios

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

在Objective C中调用另一个类的方法

我有2个类,比如A类和B类.B类是在A类中创建的.我在A类中有一个方法,需要在A类和B类中执行.在A类中调用方法本身很好.但我不确定在类B中调用该方法.我已经尝试将该方法声明为静态,但由于我不能在静态方法中使用实例变量,我认为使用委托会是一个好主意.由于我来自C#背景,我不确定在Objective C中使用它.从概念上讲,我已经在C#中实现了我需要的内容,如下所示.只是想知道在Objective C中它的等价物是什么.

class A
{

    public A()
    {
        B myclass = new B(() => calculate());                
    }

    public void calculate()
    {
        // todo
    }
}

class B
{
    public B(Action calculate)
    {
        calculate();
    }
}
Run Code Online (Sandbox Code Playgroud)

是否可以使用协议来完成此操作.

iphone delegates objective-c ios

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

内存泄漏 - UIImagePNGRepresentation

我正在尝试将图像复制UIImagePicker到文档目录.我使用@"UIImagePickerControllerOriginalImage"密钥从UIImagePickerDelegate的字典中获取原始图像.我正在使用图像写入文件UIImagePNGRepresentation.当我以高分辨率(图像大小约20 mb)添加(重复处理)图像时,我面临着内存问题.

我分析并使用了Xcode的内存泄漏功能,并放大了以下代码,这是造成泄漏的原因.

@autoreleasepool {
    imagesData = UIImagePNGRepresentation(images);
    [imagesData writeToFile:name atomically:NO];
    imagesData = nil;
    //[UIImageJPEGRepresentation(images, 1.0) writeToFile:name atomically:YES];
}
Run Code Online (Sandbox Code Playgroud)

我在这里看到很多关于内存泄漏的问题UIImagePNGRepresentation.但我没有找到解决问题的正确方法.需要帮忙.

iphone memory-leaks memory-management uiimage ios

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

单击UIAlertView时崩溃

当我单击时UIAletView,我收到以下错误.

alertView:clickedButtonAtIndex:]: message sent to deallocated instance 0x84c7010
Run Code Online (Sandbox Code Playgroud)

这是我用过的代码.

    UIAlertView  *testAlert = [[ UIAlertView alloc]initWithTitle:messageTitle message:messageBody delegate:self cancelButtonTitle:messageClose otherButtonTitles:messageTryAgain, nil];
    testAlert.tag = 2;
    [testAlert show];
    [testAlert release];
Run Code Online (Sandbox Code Playgroud)

我有委托方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

}
Run Code Online (Sandbox Code Playgroud)

单击时UIAlertView,即使在控件到达委托方法之前,应用程序也会崩溃.可能是什么原因.我究竟做错了什么?

iphone uialertview ios

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