是否可以使用SKScene阵列实现iCarousel?

时间:2014-11-27 15:46:28

标签: ios objective-c sprite-kit icarousel

我正在研究项目,我想创建包含不同场景细节的iCarousel。 为了清楚起见,我的应用程序在SKScene的XML文件中保存了它们的内容,我希望在加载之前预览所有竞技场。并认为iCarousel将是一个很好的解决方案,但我不知道是否可能。

我已经做的是: 1-I使用包含标签栏视图的Storyboard创建了一个项目。 2-一个选项卡用于SKScene和保存元素(场景工作正常,一切都在那里切换到第二个选项卡)。 3-第二个用于展示iCarousel,我应该在那里预览我的竞技场(地图)。

任何人都可以帮助并建议解决我的问题吗? 如果iCarousel是一个不错的选择。请告诉我怎么做。

1 个答案:

答案 0 :(得分:1)

在存储容量方面它有点贵,但效果很好。 这是你会得到的:

The calling view of carousel

当您点击加载竞技场时,您将获得以下视图以选择您的竞技场:

carousel view

您必须选择竞技场,然后点击绿色按钮才能返回到已加载所选竞技场的主叫视图。

以及实现目标的方法:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 //UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
selectedItem=[_Title objectAtIndex:indexPath.row];
[singleton setChoice:selectedItem];

tableSelectedItemIndexPath=indexPath; //Here we strore the selected item index so later when returninng to normal mode we can deselect the item

TableViewRef=tableView;

if([selectedItem isEqualToString:@"load arena])
{
    if ([[SpriteMyScene getMapsVector] count] == 0){

        UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Absence de carte à visualiser" message:@"Il n'y a pas de carte disponible" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];
    }

    else{

        [[[[self.tabBarController tabBar]items]objectAtIndex:2]setEnabled:TRUE];

        [self.tabBarController setSelectedIndex:2 ];
    }
}

if([selectedItem isEqualToString:@"save arena"])
{
    UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"XML Save" message:@"Enter the name of the file you wish to save." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    [alert addButtonWithTitle:@"OK"];
    [alert show];

    //We programmarically remove the selection
    [TableViewRef deselectRowAtIndexPath:tableSelectedItemIndexPath animated:YES];

}

if([selectedItem isEqualToString:@"delete arena"])
{
    int yCoordinate=40;
    //This is the scroll pan ein which the xml file list is displayed
    _polygonView = [[UIScrollView alloc] initWithFrame: CGRectMake ( 0, 0, 500, 300)];
    _polygonView.backgroundColor=[UIColor clearColor];
    [_polygonView setScrollEnabled:YES]; //we activated the scroll function

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //here we all directory paths on ios
    NSString *docDir;

    docDir=[paths objectAtIndex:0]; //this is the path to Document directory


    //we get an array containing all files in a given directory. This is same as File class in java
    NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docDir error:NULL];
    for (int i = 0; i < (int)[directoryContent count]; i++)
    {
        NSRange range;
        range=[[directoryContent objectAtIndex:i] rangeOfString:@".xml"];
        if(range.location != NSNotFound)
        {

            //this index is used ot exlude the .xml part when displaying teh name sof the files to the user
            int ToIndex=[[directoryContent objectAtIndex:i] length];
            ToIndex-=4;

            NSString *btnTitle=[[directoryContent objectAtIndex:i] substringToIndex:ToIndex];
            if(![btnTitle isEqualToString:@"imageData"])
            {
                UIButton *FileButton = [[UIButton alloc] initWithFrame:CGRectMake(165, yCoordinate, 200, 40)];
                [FileButton setTitle:btnTitle forState:UIControlStateNormal];
                [FileButton setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
                [FileButton setEnabled:YES];
                [FileButton setUserInteractionEnabled:YES];
                [FileButton addTarget: self action: @selector(buttonIsPressed:) forControlEvents: UIControlEventTouchDown];
                [FileButton setBackgroundColor:[UIColor blueColor]];
                [_polygonView addSubview:FileButton];
                yCoordinate+=45;
            }
        }

    }

    _polygonView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height *2.5);

    //This is the licensed class that is used to create a window pane
    CustomIOS7AlertView* alertView=[[CustomIOS7AlertView alloc]init];
    alertView.tag=1;
    [alertView setFrame:CGRectMake(500, 0, 500, 500)];

    [alertView setContainerView:_polygonView];
    [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Delete File", @"Cancel", nil]];
    [alertView setDelegate:self];
    [alertView show];
}

....
/*
 * This method is used ot read the user input text value when user enters the name of the xml file
 * This is used when saving a xml file
 */

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{  if (buttonIndex == 1) {

    UITextField* fileName = [alertView textFieldAtIndex:0];

    XMLHandler* xml=[[XMLHandler alloc] init];

    [xml setXmlFileName:fileName.text];

    [[SpriteViewController getSceneRef] snapShotScene:fileName.text];

    //we save the image file
    [xml generateImageFile:[SpriteMyScene getImageData]:[SpriteMyScene getImageFileName]];

    //this function gets the _nodeDictionnary as argument
    NSMutableDictionary* tmp = [singleton getSceneNodeDictionnary];

    [xml generateXML:tmp];

}}

每次用户使用此方法保存竞技场时都会拍摄照片:

- (void) snapShotScene: (NSString*) imageName{

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.50);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

@autoreleasepool
{

    //convert image into .png format.
    imageData = UIImagePNGRepresentation(image);

    imageFileName= imageName;

    [mapsVector addObject: imageData];
    [fileNamesVector addObject: imageFileName];

 }

}

对于iCarousel类,请使用以下链接:The iCarousel repository 我希望这会有所帮助。