随机 UIView 切换器
我的 iPhone 应用程序中有三个不同的视图,当用户按下按钮时,我需要将视图随机更改为三个视图中的一个。我找到了这段代码,但我不知道如何加载图像..抱歉,但我是新手....!
- (IBAction) yourBtnPressed : (id) sender
{
int i = arc4random() % 3;
if(i == 1)
{
//load first view
}
else if(i == 2)
{
//load second view
}
else
{
//load third view
}
}
I have three different views in my iPhone app, and when the user presses a button, I need the view to change to either of the three views randomly. I've found this code, but i don't know how to load images..sorry but i'm newbie....!!
- (IBAction) yourBtnPressed : (id) sender
{
int i = arc4random() % 3;
if(i == 1)
{
//load first view
}
else if(i == 2)
{
//load second view
}
else
{
//load third view
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果视图都在同一个视图控制器中,您可以简单地编写
,或者为了更酷的过渡,您可以使用这些方法
+transitionWithView:持续时间:选项:动画:完成:
+ transitionFromView:toView:duration:options:completion:
请参阅苹果文档:
http://developer.apple.com/库/IOs/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html
if view are all in the same viewcontroller you can simply write
or for more cool transition you can use these method
+ transitionWithView:duration:options:animations:completion:
+ transitionFromView:toView:duration:options:completion:
see apple documentation:
http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html
如果您的视图位于 .xib 文件中,则可以使用以下代码:
如果您想以编程方式创建视图,则:
If your views are in a .xib file you can use this code:
If you think to create your views programmatically, then: