随机 UIView 切换器

发布于 2024-12-29 18:12:18 字数 357 浏览 2 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满意归宿 2025-01-05 18:12:18

如果视图都在同一个视图控制器中,您可以简单地编写

self.view = firstView;

,或者为了更酷的过渡,您可以使用这些方法
+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

self.view = firstView;

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

可爱咩 2025-01-05 18:12:18

如果您的视图位于 .xib 文件中,则可以使用以下代码:

[self.view addSubview:aView];

如果您想以编程方式创建视图,则:

UIView *aView = [[UIView alloc] initWithFrame:aFrame];
// add contents to your aView here
[self.view addSubview:aView];
[aView release]; // if you don't need it anymore

If your views are in a .xib file you can use this code:

[self.view addSubview:aView];

If you think to create your views programmatically, then:

UIView *aView = [[UIView alloc] initWithFrame:aFrame];
// add contents to your aView here
[self.view addSubview:aView];
[aView release]; // if you don't need it anymore
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文