gpt4 book ai didi

ios - 当用户选择 "Play Tutorial Again"时,从应用内设置再次播放 iOS 应用内教程

转载 作者:行者123 更新时间:2023-11-29 12:50:02 27 4
gpt4 key购买 nike

我创建了一个简单的 iPhone 应用程序,当用户第一次下载该应用程序时,他们可以单击“下一步”并循环浏览图像。目前没有办法再次播放教程,但在我的更新中,我想介绍这个功能,一些类似的应用程序在应用程序本身的设置中。

我有一个 Tab Bar,其中包含三个 table view controllers TimelineEventSettings。当用户转到 Settings tab 并选择“Play Tutorial Again”表格 View 单元格时, 我希望它再次开始教程。

在我的 Timeline View ( Root View )中,我有以下代码:

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([TutorialViewController hasSeenTutorial] == NO) {
NSArray *tutorialImages = @[[UIImage imageNamed:@"Tutorial 1.png"],
[UIImage imageNamed:@"Tutorial 2.png"],
[UIImage imageNamed:@"Tutorial 3.png"],
[UIImage imageNamed:@"Tutorial 4.png"],
[UIImage imageNamed:@"Tutorial 5.png"]];
TutorialViewController *tutorial = [[TutorialViewController alloc] initWithImages:tutorialImages];
[self presentViewController:tutorial animated:YES completion:nil];
[TutorialViewController setHasSeenTutorial:YES];
}
}

- (void)displayTutorial
{

NSArray *tutorialImages = @[[UIImage imageNamed:@"Tutorial 1.png"],
[UIImage imageNamed:@"Tutorial 2.png"],
[UIImage imageNamed:@"Tutorial 3.png"],
[UIImage imageNamed:@"Tutorial 4.png"],
[UIImage imageNamed:@"Tutorial 5.png"]];

TutorialViewController *tutorial = [[TutorialViewController alloc] initWithImages:tutorialImages];
[self presentViewController:tutorial animated:YES completion:nil];
}

TutorialViewController 的代码是:

static NSString * const kHasSeenTutorial = @"hasSeenTutorial";

+ (BOOL)hasSeenTutorial
{
return [[NSUserDefaults standardUserDefaults] boolForKey:kHasSeenTutorial];
}

+ (void)setHasSeenTutorial:(BOOL)hasSeenTutorial
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:hasSeenTutorial forKey:kHasSeenTutorial];
[defaults synchronize];
}

- (id)initWithImages:(NSArray *)imageArray
{
self = [super init];
if (self) {
if (imageArray == nil) {
[[NSException exceptionWithName:NSInvalidArgumentException reason:@"imageArray cannot be nil." userInfo:nil] raise];
}
self.images = imageArray;
}
return self;
}

- (void)loadView
{
[super loadView];
}

- (void)viewDidLoad
{

[super viewDidLoad];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.view addSubview:imageView];
self.imageView = imageView;

CGRect buttonFrame = [[UIScreen mainScreen] bounds];

buttonFrame.origin.y = 519.0;
buttonFrame.origin.x = 250.0;
buttonFrame.size.height = 51.0;
buttonFrame.size.width = 70.0;

UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[nextButton setTitle:@"Next" forState:UIControlStateNormal];
[nextButton addTarget:self action:@selector(nextButtonWasTapped:) forControlEvents:UIControlEventTouchUpInside];

nextButton.frame = buttonFrame;
nextButton.backgroundColor = [UIColor whiteColor];

nextButton.showsTouchWhenHighlighted = YES;
nextButton.adjustsImageWhenHighlighted = NO;
nextButton.tintColor = [UIColor purpleColor];
nextButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
nextButton.opaque = NO;

[self.view addSubview:nextButton];
self.nextButton = nextButton;

// ----------------------------------------------------------------------

currentIndex = 0;

if (self.images == nil) {
self.images = @[];
}


}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self resetToStart];
}

- (void)setImages:(NSArray *)images
{
_images = images;
[self resetToStart];
}

- (void)resetToStart
{
[self.nextButton setTitle:@"Next" forState:UIControlStateNormal];
currentIndex = 0;
if (currentIndex < self.images.count) {
self.imageView.image = self.images[currentIndex];
}

[self.view bringSubviewToFront:self.nextButton];
}

- (void)nextButtonWasTapped:(id)sender
{
currentIndex++;
if (currentIndex < self.images.count) {
self.imageView.image = self.images[currentIndex];

if (currentIndex == self.images.count - 1) {
[self.nextButton setTitle:@"Start" forState:UIControlStateNormal];
}
}

if (currentIndex == self.images.count) {
[self dismissViewControllerAnimated:YES completion:nil];
[EnvylopeTutorialViewController setHasSeenTutorial:YES];
}
}

从表面上看,我猜我会做一些类似调用 ResetToStart 或类似的事情,但我真的不确定我会怎么做。图像是在时间轴中传达的,但我正在从设置中播放教程,所以我猜我必须在设置 TableView 等中设置一些类似的方法。我真的迷失了这一点

因此,在“设置”选项卡中,我希望能够通过单击“播放教程”表格 View 单元格,使用相同的图像、按钮等重新播放教程。

在 App Settings View Controller 中,我有:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell.textLabel.text isEqualToString:@"Play Tutorial Again"])
{
NSLog(@"The Tutorial is going to play");
[self displayTutorial];
}


}

但是没有调用 displayTutorial 方法。

任何关于这方面的指导将不胜感激。

最佳答案

只需在设置 View 中使用 didSelectRow 调用您的 Tutorial 代码,省略 hasSeenTutorial 代码

TutorialViewController *tutorial = [[TutorialViewController alloc] initWithImages:tutorialImages]; 放在您的 settingsViewController 的 didSelectRow 方法中,以便随时显示教程

关于ios - 当用户选择 "Play Tutorial Again"时,从应用内设置再次播放 iOS 应用内教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22632498/

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