如何在xcode中制作宾果板?

时间:2013-10-12 20:18:58

标签: ios objective-c ios7 xcode5

在我为iPhone开发的游戏中,我想创建一个宾果板,您可以在其中单击其中一个点,然后打开相机。我有相机部件,但我正在制作电路板。我认为带有25个项目的Collection View可以用于网格,但是当应用程序运行时屏幕上没有任何内容出现。是否有更好的方法来制作餐桌?

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}

- (IBAction)cameraButtonClicked:(id)sender {
    if (![UIImagePickerController isSourceTypeAvailable:(UIImagePickerControllerSourceTypeCamera)]) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Camera Not Available" message:@"The camera feature isn't available on your device." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
        [alertView show];
    }else{
        //Show the Image Picker Controller Here
        UIImagePickerController * ipc = [[UIImagePickerController alloc] init];
        ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
        ipc.allowsEditing = NO;
        //Set the Delegate
        ipc.delegate = self;

        [self.navigationController presentViewController:ipc animated:YES completion:nil];
    }
}

#pragma mark ImagePicker Delegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:nil];

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    self.imageView.image = image;
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end

1 个答案:

答案 0 :(得分:1)

我认为使用多个视图或自定义绘图可以更好地实现宾果游戏板。我个人会选择自定义绘图,因为我很舒服。关于你的收藏视图的想法,它可能不是最好的唯一原因是因为对项目间距的控制较少。根据我的经验,很难让物品彼此之间立即坐下。我会沿着每条潜在路线走下去,给你2美分:

1。集合视图

做一些关于布置完美对齐网格的研究。您可能必须拥有自定义布局或更改集合视图插图和/或minimumInteritemSpacing。请参阅以下SO帖子:

2。手动放置的视图

如果您知道您将只拥有一定数量的宾果游戏“广告位”或“广场”,此技术将有效。您可以在代码,故事板或xib中创建它。

3。自定义绘图/布局

由于其灵活性,我会提倡这种技术。您可以传递所需的宾果图块数量,然后使用平坦的瓷砖外观或按钮样式UIButtons构建UIButtonTypeCustom。另一种自定义绘图方式是使用CoreGraphics绘制。但是,这不适合清除UIButton之类的操作,并且需要您重新实现触摸方法。

结论

我会尝试使用集合视图,如果你可以得到项目间距,或者我会使用代码中列出的计算视图,或者如果你有一个固定数量的项目然后在故事板中布局什么的。