Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何创建较大的子视图_Iphone_Objective C_Xcode_Uiview_Subview - Fatal编程技术网

Iphone 如何创建较大的子视图

Iphone 如何创建较大的子视图,iphone,objective-c,xcode,uiview,subview,Iphone,Objective C,Xcode,Uiview,Subview,我希望创建一个相当大的子视图,可以像这样拖动: #import "ThirdViewController.h" @interface SecondViewController () @property (retain) ThirdViewController *thirdViewConroller; - (void)buttonTap; @end @implementation SecondViewController @synthesize thirdViewConroller =

我希望创建一个相当大的子视图,可以像这样拖动:

#import "ThirdViewController.h"

@interface SecondViewController ()

@property (retain) ThirdViewController *thirdViewConroller;

- (void)buttonTap;

@end

@implementation SecondViewController

@synthesize thirdViewConroller = _thirdViewConroller;

- (void)dealloc {
    self.thirdViewConroller = nil;
    [super dealloc];
}

- (void)loadView {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.titleLabel.text = @"Show third controller";
    [button addTarget:self action:@selector(buttonTap) forControlEvents:UIControlEventTouchUpInside];
    button.frame = // Some CGRect of where you want the button to be
    [self.view addSubview:button];
}

- (void)buttonTap {
    // When the button is tapped, create an instance of your ThirdViewController and add it
    self.thirdViewConroller = [[ThirdViewController alloc] initWithFrame:/* Some CGRect where you want the controller to be */ ];
    [self.thirdViewConroller willMoveToParentViewController:self];
    [self addChildViewController:self.thirdViewConroller];
    [self.thirdViewConroller didMoveToParentViewController:self];
}

@end

如果有一个iAction将您带到下一个视图(SecondViewController),当它这样做时,那里会有另一个iAction,当您单击该iAction时,它将创建一个子视图,该子视图的大小约为当前屏幕(SecondViewController)的一半,显示将要创建的第三个视图控制器?另外,如何使子视图可拖动?谢谢您的帮助。

对不起,我想澄清一下,您希望第二个视图控制器上有一个按钮,当点击该按钮时,第三个视图控制器将占据底部屏幕的一半

如果是这种情况,那么您可以使用iOS5中的新视图控制器容器来执行此操作

好的,您有三个视图控制器。为此,我们假设您的类被称为FirstViewController、SecondViewController和ThirdViewController

根据您所说的,我假设您已经有了带有按钮的FirstViewController实例,这会将您移动到SecondViewController实例,然后问题是当按下按钮时,SecondViewController将ThirdViewController的实例添加到屏幕的下半部分

SecondViewController的.m文件需要执行以下操作:

#import "ThirdViewController.h"

@interface SecondViewController ()

@property (retain) ThirdViewController *thirdViewConroller;

- (void)buttonTap;

@end

@implementation SecondViewController

@synthesize thirdViewConroller = _thirdViewConroller;

- (void)dealloc {
    self.thirdViewConroller = nil;
    [super dealloc];
}

- (void)loadView {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.titleLabel.text = @"Show third controller";
    [button addTarget:self action:@selector(buttonTap) forControlEvents:UIControlEventTouchUpInside];
    button.frame = // Some CGRect of where you want the button to be
    [self.view addSubview:button];
}

- (void)buttonTap {
    // When the button is tapped, create an instance of your ThirdViewController and add it
    self.thirdViewConroller = [[ThirdViewController alloc] initWithFrame:/* Some CGRect where you want the controller to be */ ];
    [self.thirdViewConroller willMoveToParentViewController:self];
    [self addChildViewController:self.thirdViewConroller];
    [self.thirdViewConroller didMoveToParentViewController:self];
}

@end
这将在第二个控制器上为您提供一个按钮,该按钮将创建并添加第三个控制器。确保你给我们提供你以前使用过的所有标准方法,这应该是对你现有方法的补充

在ThirdViewController的界面中:

@interface ThirdViewController : UIViewController <NSObject>
    - (id)initWithFrame:(CGRect)frame;
@end
- (id)initWithFrame:(CGRect)frame {
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        self.view.frame = frame;
        // Do your init stuff here
    }
    return self;
}
然后,它应该处理添加视图等问题

确保第三个DViewController类具有有效的initWithFrame:initialiser方法


如果您需要任何进一步的帮助,请告诉我:)

对不起,请澄清,您希望您的第二视图控制器有一个按钮,当点击该按钮时,将添加占底部屏幕一半的第三视图控制器

如果是这种情况,那么您可以使用iOS5中的新视图控制器容器来执行此操作

好的,您有三个视图控制器。为此,我们假设您的类被称为FirstViewController、SecondViewController和ThirdViewController

根据您所说的,我假设您已经有了带有按钮的FirstViewController实例,这会将您移动到SecondViewController实例,然后问题是当按下按钮时,SecondViewController将ThirdViewController的实例添加到屏幕的下半部分

SecondViewController的.m文件需要执行以下操作:

#import "ThirdViewController.h"

@interface SecondViewController ()

@property (retain) ThirdViewController *thirdViewConroller;

- (void)buttonTap;

@end

@implementation SecondViewController

@synthesize thirdViewConroller = _thirdViewConroller;

- (void)dealloc {
    self.thirdViewConroller = nil;
    [super dealloc];
}

- (void)loadView {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.titleLabel.text = @"Show third controller";
    [button addTarget:self action:@selector(buttonTap) forControlEvents:UIControlEventTouchUpInside];
    button.frame = // Some CGRect of where you want the button to be
    [self.view addSubview:button];
}

- (void)buttonTap {
    // When the button is tapped, create an instance of your ThirdViewController and add it
    self.thirdViewConroller = [[ThirdViewController alloc] initWithFrame:/* Some CGRect where you want the controller to be */ ];
    [self.thirdViewConroller willMoveToParentViewController:self];
    [self addChildViewController:self.thirdViewConroller];
    [self.thirdViewConroller didMoveToParentViewController:self];
}

@end
这将在第二个控制器上为您提供一个按钮,该按钮将创建并添加第三个控制器。确保你给我们提供你以前使用过的所有标准方法,这应该是对你现有方法的补充

在ThirdViewController的界面中:

@interface ThirdViewController : UIViewController <NSObject>
    - (id)initWithFrame:(CGRect)frame;
@end
- (id)initWithFrame:(CGRect)frame {
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        self.view.frame = frame;
        // Do your init stuff here
    }
    return self;
}
然后,它应该处理添加视图等问题

确保第三个DViewController类具有有效的initWithFrame:initialiser方法


如果您需要任何进一步的帮助,请告诉我:)

忘记提及,如果您不使用ARC,则还需要编辑此文件以进行适当的内存管理!我不太确定在哪里实现这个。目前你有3个不同的视图控制器子类吗?这是我从你的原始帖子中得到的想法?将更新答案,希望会更有帮助。SecondViewController:Warn:Instance method'-addSubView:'未找到(返回类型默认为'id')警告:“ThirdViewController”可能不响应“initWithFrame”ThirdViewController:错误:例如,接收器类型“UIViewController”没有使用选择器“initWithFrame:”声明方法错误和警告:使用ARC不允许将Objective-C点隐式转换为“void”,警告说void方法“initWithFrame:”不应返回一个值忘了提及,如果您不使用ARC,那么您还需要编辑此值以进行适当的内存管理!我不太确定在哪里实现这个。目前你有3个不同的视图控制器子类吗?这是我从你的原始帖子中得到的想法?将更新答案,希望会更有帮助。SecondViewController:Warn:Instance method'-addSubView:'未找到(返回类型默认为'id')警告:“ThirdViewController”可能不响应“initWithFrame”ThirdViewController:错误:例如,接收器类型“UIViewController”没有使用选择器“initWithFrame:”声明方法错误和警告:使用ARC不允许将Objective-C点隐式转换为“void”,警告说void方法“initWithFrame:”不应返回价值