Cocos2d中自定义UIAlertView的问题

时间:2011-11-18 02:36:53

标签: cocos2d-iphone uialertview

enter image description here

我正在尝试在Cocos2d中为UIAlertView的背景图像顶部放置按钮。它不能使用下面的代码。有什么建议吗?

UIAlertView *Win=[[UIAlertView alloc] initWithTitle:@"You Win" message:nil delegate:self cancelButtonTitle:@"Next" otherButtonTitles:@"Replay",@"Quit", nil];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(-50, -30, 400, 300)];

    NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"levelcleared.png"]];
    UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];


    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(20, 200, 70, 70)];

    NSString *path2= [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"alertviewhome.png"]];
    UIImage *bkgImg2 = [[UIImage alloc] initWithContentsOfFile:path2];

    imageView2.
    [imageView setImage:bkgImg];
    [imageView2 setImage:bkgImg2];

    [bkgImg release];
    [path release];

    [Win addSubview:imageView];
    [Win addSubview:imageView2];


    [imageView release];


    [Win show];
    [Win release];

1 个答案:

答案 0 :(得分:1)

您应该编写自己的类似警报的视图(可以将其作为子视图添加到要显示的任何视图中),并且不要将UIAlertView用于您要执行的操作。

Apple documentation for UIAlertView说:

  

此类的视图层次结构是私有的,不得修改。

对我而言,这意味着如果您尝试添加子视图(例如那些按钮或图像或其他内容),您可能会出现棘手/意外/粗略结果。