是否可以使用 SKScene 数组实现 iCarousel?
Posted
技术标签:
【中文标题】是否可以使用 SKScene 数组实现 iCarousel?【英文标题】:is it possible to implement iCarousel with SKScene array? 【发布时间】:2014-11-27 15:46:27 【问题描述】:我正在做一个项目,我想创建包含不同场景细节的 iCarousel。 需要明确的是,我的应用程序将竞技场及其内容保存在来自 SKScene 的 XML 文件中,我想在加载它们之前预览所有竞技场。并认为 iCarousel 会是一个很好的解决方案,但我不知道是否可能。
我已经做的是: 1-我使用包含标签栏视图的 Storyboard 创建了一个项目。 2- 一个选项卡用于 SKScene 和保存元素(场景运行良好,一切都可以切换到第二个选项卡)。 3- 第二个用于展示 iCarousel,我应该在其中预览我的竞技场(地图)。
谁能帮助我的问题并提出解决方案? 如果 iCarousel 是一个不错的选择。请告诉我该怎么做。
【问题讨论】:
使用 iCarousel 呈现关卡或竞技场是一个不错的选择。但是,最好先尝试一下,然后在遇到问题时提出问题。 【参考方案1】:就存储容量而言,它有点贵,但效果很好。 以下是您将得到的:
当您点击加载竞技场时,您将获得以下视图来选择您的竞技场:
您必须选择竞技场并单击绿色按钮以返回加载所选竞技场的调用视图。
这是实现它的方法:
-(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 我希望这会有所帮助。
【讨论】:
以上是关于是否可以使用 SKScene 数组实现 iCarousel?的主要内容,如果未能解决你的问题,请参考以下文章
在 SKScene 上运行 SKTransition 是不是会破坏源 SKScene?
如何在 Swift Playgrounds 中使用带有纹理的 SKNode 设置 SKScene?
将 SKScene 添加到 UIViewController?
如何在 MyScene(SKScene 的子类)中打开 xib 或故事板窗口?