gpt4 book ai didi

ios - 是否可以使用 SKScene 数组实现 iCarousel?

转载 作者:行者123 更新时间:2023-11-29 12:32:53 24 4
gpt4 key购买 nike

我正在做项目,我想创建包含不同场景细节的 iCarousel。需要明确的是,我的应用程序将竞技场及其内容保存在 SKScene 的 XML 文件中,我想在加载它们之前预览所有竞技场。并认为 iCarousel 会是一个很好的解决方案,但我不知道是否可行。

我已经做的是:1-I 使用包含选项卡栏 View 的 Storyboard 创建了一个项目。2- 一个选项卡用于 SKScene 和保存元素(场景运行良好,所有内容都可以切换到第二个选项卡)。3- 第二个用于展示 iCarousel,我应该在其中预览我的竞技场( map )。

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

最佳答案

它在存储容量方面有点贵,但效果很好。以下是您将获得的:

The calling view of carousel

当您点击加载竞技场时,您将看到以下 View 以选择您的竞技场:

carousel view

您必须选择竞技场并单击绿色按钮以返回到已加载所选竞技场的调用 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我希望这会有所帮助。

关于ios - 是否可以使用 SKScene 数组实现 iCarousel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27174406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com