一张 iPhone 地图标注中包含 2 条线条和按钮

发布于 2024-11-18 22:05:51 字数 173 浏览 3 评论 0原文

我对 xcode 和 iPhone 开发相当陌生,我想知道是否可以基本上使用一行文本和最右侧的按钮来获取标准地图标注,并在一个标注中将其加倍。因此,它是一个双高标注气泡,两行文本彼此重叠,每行最右侧都有一个按钮。实际上,我希望第一个转到详细信息页面,第二个提供注释的方向。有没有一种方法可以按照描述进行自定义标注而又不会变得太复杂?

I'm fairly new to xcode and iPhone development and I'm wondering if it's possible to basically take your standard map callout with one line of text with a button at the far right, and double that within one callout. So it's one double-high callout bubble with two lines of text on top of each other, each one with a button at the far right of it. Practically, I would like the first one to go to a details page and the second one to offer directions to the annotation. Is there a way to make a custom callout as described without getting too complicated?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

戴着白色围巾的女孩 2024-11-25 22:05:52
-(void)viewDidLoad
{

    rightimg.alpha=0;
    wrongimg.alpha=0;
    [scorelable setFont:[UIFont fontWithName:@"Helvetica" size:20]];

    quiz_array = [[NSMutableArray alloc]initWithObjects:@"which animal is called lion?",@"TigerDance_mov_02.png",@"LionDance_mov_11.png",@"cheethau.png",@"1",@"in these three which is the dog?",@"DogLooking_mov_36.png",@"UnicornLeggingSingleLeg_mov_09.png",@"ZeebraHeadShake_ioc_23.png",@"1",@"which animal most humans likes or pets?",@"PigWalk_ioc_08.png",@"RabbitHeadShake_ioc_10.png",@"dog.png",@"3",@"which kind of birds will keep in the houses?",@"egg.png",@"red.png",@"parrot.png",@"3",@"in these which animal are called domestic animal?",@"LionDance_mov_11.png",@"CowWalk_mov_01.png",@"TigerDance_mov_02.png",@"2",@"in these which animals are called wild animals?",@"cow2.png",@"black-horse-black_horse.jpg",@"deer.png",@"3",@"which animal moves slowly?",@"Three.png",@"turtile.png",@"snail.png",@"3",@"which animals eats veg or grass and leaves?",@"deer.png",@"dog.png",@"cat.png",@"1",nil];


    NSString *selected = [quiz_array  objectAtIndex:row];


       NSString *activeQuestion = [[NSString alloc] initWithFormat:@"%d . %@",questionnumber,selected];


    rightAnswer = [[quiz_array objectAtIndex:row+4] intValue];

    [answerimg1 setImage:[UIImage imageNamed:[quiz_array objectAtIndex:row+1]]];
    [answerimg2 setImage:[UIImage imageNamed:[quiz_array objectAtIndex:row+2]]];
    [answerimg3 setImage:[UIImage imageNamed:[quiz_array objectAtIndex:row+3]]];

        correctOption = [quiz_array objectAtIndex:(row+rightAnswer)];


    questionlbl.text = activeQuestion;

}
-(void)viewDidLoad
{

    rightimg.alpha=0;
    wrongimg.alpha=0;
    [scorelable setFont:[UIFont fontWithName:@"Helvetica" size:20]];

    quiz_array = [[NSMutableArray alloc]initWithObjects:@"which animal is called lion?",@"TigerDance_mov_02.png",@"LionDance_mov_11.png",@"cheethau.png",@"1",@"in these three which is the dog?",@"DogLooking_mov_36.png",@"UnicornLeggingSingleLeg_mov_09.png",@"ZeebraHeadShake_ioc_23.png",@"1",@"which animal most humans likes or pets?",@"PigWalk_ioc_08.png",@"RabbitHeadShake_ioc_10.png",@"dog.png",@"3",@"which kind of birds will keep in the houses?",@"egg.png",@"red.png",@"parrot.png",@"3",@"in these which animal are called domestic animal?",@"LionDance_mov_11.png",@"CowWalk_mov_01.png",@"TigerDance_mov_02.png",@"2",@"in these which animals are called wild animals?",@"cow2.png",@"black-horse-black_horse.jpg",@"deer.png",@"3",@"which animal moves slowly?",@"Three.png",@"turtile.png",@"snail.png",@"3",@"which animals eats veg or grass and leaves?",@"deer.png",@"dog.png",@"cat.png",@"1",nil];


    NSString *selected = [quiz_array  objectAtIndex:row];


       NSString *activeQuestion = [[NSString alloc] initWithFormat:@"%d . %@",questionnumber,selected];


    rightAnswer = [[quiz_array objectAtIndex:row+4] intValue];

    [answerimg1 setImage:[UIImage imageNamed:[quiz_array objectAtIndex:row+1]]];
    [answerimg2 setImage:[UIImage imageNamed:[quiz_array objectAtIndex:row+2]]];
    [answerimg3 setImage:[UIImage imageNamed:[quiz_array objectAtIndex:row+3]]];

        correctOption = [quiz_array objectAtIndex:(row+rightAnswer)];


    questionlbl.text = activeQuestion;

}
不交电费瞎发啥光 2024-11-25 22:05:51

查看异步解决方案博客对于标注替换实现,尽管这可能比您想要做的工作更多。我认为没有一种简单的方法可以做你想做的事。

Check out the Asynchrony Solutions Blog for a callout replacement implementation, though it may be more work than you're looking to do. I don't think there's a simple easy way to do what you want.

圈圈圆圆圈圈 2024-11-25 22:05:51

您可以实现委托方法、viewForAnnotation,如下所示

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{

MKAnnotationView *view = nil; 

if(annotation !=mapView.userLocation){
    view = (MKAnnotationView *) 
    [mapView dequeueReusableAnnotationViewWithIdentifier:@"identifier"]; 
    if(nil == view) { 
        view = [[[MKAnnotationView alloc] 
                 initWithAnnotation:annotation reuseIdentifier:@"identifier"] 
                autorelease];           
    }   
    //Custom class for showing title and subtitle
    ParkPlaceMark *currPlaceMark = annotation;

        view.image = [UIImage imageNamed:@"pin.png"];

            //Button at far right corner.
    UIButton *btnViewVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    view.rightCalloutAccessoryView=btnViewVenue;
    view.enabled = YES;
    view.canShowCallout = YES;
    view.multipleTouchEnabled = NO;

}       
return view;
}

注释的自定义类如下

@interface ParkPlaceMark : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *m_title;
NSString *m_subTitle;
int position;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, readwrite) int position;
-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;
- (NSString *)subtitle;
- (NSString *)title;
- (void)setTitle:(NSString *)title;
- (void)setSubTitle:(NSString *)subtitle;

@end

注释的自定义类实现

@implementation ParkPlaceMark
@synthesize coordinate;
@synthesize position;

- (NSString *)subtitle{
return m_subTitle;
}
- (NSString *)title{
return m_title;
}
- (void)setTitle:(NSString *)title{
m_title = title;
}
- (void)setSubTitle:(NSString *)subtitle{
m_subTitle = subtitle;
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
coordinate=c;
NSLog(@"%f,%f",c.latitude,c.longitude);
return self;
}
@end

You can implement delegate method, viewForAnnotation as below

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{

MKAnnotationView *view = nil; 

if(annotation !=mapView.userLocation){
    view = (MKAnnotationView *) 
    [mapView dequeueReusableAnnotationViewWithIdentifier:@"identifier"]; 
    if(nil == view) { 
        view = [[[MKAnnotationView alloc] 
                 initWithAnnotation:annotation reuseIdentifier:@"identifier"] 
                autorelease];           
    }   
    //Custom class for showing title and subtitle
    ParkPlaceMark *currPlaceMark = annotation;

        view.image = [UIImage imageNamed:@"pin.png"];

            //Button at far right corner.
    UIButton *btnViewVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    view.rightCalloutAccessoryView=btnViewVenue;
    view.enabled = YES;
    view.canShowCallout = YES;
    view.multipleTouchEnabled = NO;

}       
return view;
}

Custom class for Annotation as below

@interface ParkPlaceMark : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *m_title;
NSString *m_subTitle;
int position;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, readwrite) int position;
-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;
- (NSString *)subtitle;
- (NSString *)title;
- (void)setTitle:(NSString *)title;
- (void)setSubTitle:(NSString *)subtitle;

@end

Custom class implementation of Annotation

@implementation ParkPlaceMark
@synthesize coordinate;
@synthesize position;

- (NSString *)subtitle{
return m_subTitle;
}
- (NSString *)title{
return m_title;
}
- (void)setTitle:(NSString *)title{
m_title = title;
}
- (void)setSubTitle:(NSString *)subtitle{
m_subTitle = subtitle;
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
coordinate=c;
NSLog(@"%f,%f",c.latitude,c.longitude);
return self;
}
@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文