iphone:以编程方式展开和折叠UIView [英] iphone: expand and collapse a UIView programmatically

查看:244
本文介绍了iphone:以编程方式展开和折叠UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone / iPad开发的新手。
你可以帮助我以编程方式创建这个。我想以编程方式扩展/折叠UIView。

I am very new to iPhone/iPad development. can you please help me create this programmatically. I want to expand/collapse a UIView programmatically.

这个可展开/可折叠的视图将有一些文本字段和标签,它们应该随该视图出现和消失

This expandable/collapsable view will have some text field and lables which should appear and disappear with that view

推荐答案

假设您在UIViewController类中有一个UIView实例,如下所示:

Suppose you have a UIView instance in the UIViewController class like this:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, w1, h1)];
[self.view addSubview:view];

根据您在此处设置视图可见性的要求..我没有显示视图当控制器加载它的视图时..

based on the requirement you set the view visibility as I did here .. I am not displaying the view when the controller is loading it's view ..

[view setHidden:YES];

维护一个标志以检查视图实例的可见性..让我们说 isViewVisible 是我的标志,用于检查视图的可见性..我在开始时将其设置为NO ..

Maintain a flag to check the visibility of the view instance .. lets say isViewVisible is my flag to check the visibility of the view .. I set it to NO in the begning ..

isHelpViewVisible = NO;

我在这里写了一个动作方法(viewClicked)来展开和折叠视图对象,给这个按钮实例的动作方法,它将起作用。

and I wrote an action method (viewClicked) here to expand and to collapse the view object , give this action method to a button instance and it will work.

- (void)viewClicked:(id)sender {

    if (!isViewVisible) {
        isViewVisible = YES;
        [view setHidden:NO];
        [UIView beginAnimations:@"animationOff" context:NULL]; 
        [UIView setAnimationDuration:1.3f];
        [view setFrame:CGRectMake(x, y, w1, h1)];
        [UIView commitAnimations];
    } else {
        isViewVisible = NO;
        [view setHidden:NO];
        [UIView beginAnimations:@"animationOff" context:NULL]; 
        [UIView setAnimationDuration:1.3f];
        [view setFrame:CGRectMake(x, y, width, hight)];
        [UIView commitAnimations];
    }

}

并添加文本字段和标签对象视图对象作为子视图,并将动画设置为这些对象..它将起作用。

and add the textfields and labels objects to the view object as subviews and set the animation to those objects as well .. it will work.

这篇关于iphone:以编程方式展开和折叠UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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