在 iPhone 应用程序中使用按钮切换视图 [英] Switch Views with button in iPhone App

查看:35
本文介绍了在 iPhone 应用程序中使用按钮切换视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是一个 iPhone 编程菜鸟(我知道这不是很有帮助).但我确实会说英语:)

Firstly, I am an iPhone programming noob (I know that's not very helpful). But I do speak english :).

我正在制作一个基本上是音板的应用,也就是说,你按下一个按钮,它就会播放声音效果.

I am making an app that is basically a soundboard, that is you press a button and it plays a sound effect.

我想添加的一件事是在播放声音时出现的视图,上面写着当前正在播放声音,请点击任意位置停止".我这样做的方法是截取普通屏幕的屏幕截图,在 Microsoft Word 中放置一个透明的黑色方块(我知道,很棒的图形程序,对吧?)然后使用它.看起来不错.

One thing I wanted to add was a view which came up when a sound was playing, that said something like "A sound is currently being played, please tap anywhere to stop". The way I did this was take a screenshot of the normal screen, put a transparent black square over it in Microsoft Word (I know, great graphics program, right?) and use that. It looks fine.

我想知道如何制作它,以便当您按下按钮播放声音时,它不仅会播放声音,而且还会将视图切换到上述第二个视图.然后,如果该人在第二个视图中触摸屏幕,它将切换回第一个视图,并停止播放(我认为最好的方法是在viewDidLoad"中使用某种停止播放"方法" 第一个视图的部分).

I was wondering how to make it so that when you press a button to play the sound, not only does it play the sound, but it also switches views to the second view described above. Then, if the person touched the screen in the second view, it would switch back to the first view, and stop playing (I assume the best way to do this would be to have some kind of 'stop playing" method in the "viewDidLoad" section of the first view).

如果有人能告诉我如何做出一个在按下按钮时调用的操作来切换视图,我将不胜感激.我不需要任何花哨的导航栏停留或其他什么,我只需要它来切换视图.

I would very much appreciate it if someone could tell me how to make an action which is called when a button is pushed, that switches views. I don't need any fancy navigation bar staying up or whatever, I just need it to switch views.

另外,我的应用程序是一个基于视图的应用程序,我目前有以下文件:

Also, my application is a view based application, and I currently have the following files:

课程:(appname)appdelegate (.h & .m),(appname)viewcontroller (.h & .m), (我的主窗口)playController (.h & .m), (我的第二个窗口)

Classes: (appname)appdelegate (.h & .m), (appname)viewcontroller (.h & .m), (my main window) playingController (.h & .m), (my second window)

资源:(appname)viewcontroller.xib(主窗口IB文件)play.nib(第二个窗口 IB 文件)mainwindow.nib(不知道这是做什么的,真的不在乎).

Resources: (appname)viewcontroller.xib (main window IB file) playing.nib (second window IB file) mainwindow.nib (no Idea what this does, don't really care).

我认为这些适用于应用程序,但我可能完全错了.请告诉我是否需要其他文件,或者是否需要重命名这些文件.

I think that these will work for the app, but I'm probably totally wrong. Please tell me if I need additional files, or if I need to rename these files.

非常感谢,

卢克

推荐答案

尝试在整个视图上放置一个不可见的按钮以返回到第一个视图

Try placing an invisible button over the entire view to get back to the first view

要进入任何屏幕,请使用以下内容:

to get to any screen use something like this:

SecondScreen *second = [[SecondScreen alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];

步骤:1 转到界面生成器(双击 .xib 文件)2 在屏幕上拖动一个 UIButton3 转到代码4 转到.h文件并写入

Steps: 1 Go to interface builder (double click .xib file) 2 Drag a UIButton on screen 3 Go to code 4 Go to .h file and write

-(IBAction) switchViews:(id)sender;

5 转到 .m 文件并输入

5 GO to .m file and type in

-(IBAction) switchViews:(id)sender
{
    SecondScreen *second = [[SecondScreen alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:second animated:YES];
}

6 在界面生成器中,单击按钮,按住 CONTROL 并一直拖动(显示一条线)到 FileOwner.7 从列表中选择 switchViews 方法

6 In interface builder, click the button, Hold CONTROL and Drag all the way (a line shows) to the FileOwner. 7 Choose switchViews method from list

gl

这篇关于在 iPhone 应用程序中使用按钮切换视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆