我正在研究项目,我想创建包含不同场景细节的iCarousel。
需要明确的是,我的应用程序将竞技场及其内容保存在来自SKScene的XML文件中,我希望在加载它们之前先预览所有竞技场。并认为iCarousel将是一个很好的解决方案,但我不知道是否可能。
我已经做的是:
1-I用Storyboard创建了一个包含标签栏视图的项目。
2-一个选项卡用于SKScene和保存元素(场景运行正常,所有内容都可以切换到第二个选项卡)。
3-第二个用于展示iCarousel,我应该在此处预览我的竞技场( map )。
谁能帮助我并为我的问题提供解决方案?
如果iCarousel是一个不错的选择。请告诉我该怎么做。
最佳答案
就存储容量而言,这有点贵,但它可以完美运行。
这是您将得到的:
单击加载竞技场时,将显示以下视图以选择您的竞技场:
您必须选择竞技场,然后单击绿色按钮以返回加载了所选竞技场的调用视图。
这是实现它的方法:
-(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
我希望这将有所帮助。
关于ios - 可以用SKScene数组实现iCarousel吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27174406/