Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Ios 在景观中不显示图像和按钮_Ios_Objective C_Iphone - Fatal编程技术网

Ios 在景观中不显示图像和按钮

Ios 在景观中不显示图像和按钮,ios,objective-c,iphone,Ios,Objective C,Iphone,我在代码中添加了一个imageview,在一个视图控制器中添加了两个按钮。在纵向模式下,它工作得很好。但在横向模式下,无法看到图像和按钮 @implementation ViewController { UIImageView* imgView; // your UIImageView } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the vi

我在代码中添加了一个imageview,在一个视图控制器中添加了两个按钮。在纵向模式下,它工作得很好。但在横向模式下,无法看到图像和按钮

@implementation ViewController {
    UIImageView* imgView; // your UIImageView
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [[self navigationController] setNavigationBarHidden:YES animated:YES];

    UIImage* img1 = [UIImage imageNamed:@"11.jpg"];
    UIImage* img2 = [UIImage imageNamed:@"s2.jpg"];


    imgView = [[UIImageView alloc] initWithFrame:self.view.frame]; // create a UIImageView with the same size as the view.
    imgView.animationImages = @[img1, img2]; // use a nice NSArray literal to pass in your images.
    imgView.animationDuration = 2.0*2.0; // 2 seconds for each image (x3 images)
    [self.view addSubview:imgView]; // add UIImageView to view

    [imgView startAnimating]; // start animating

 // button one
    UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-50, self.view.frame.size.width/2 , 50.0)];

    [button setBackgroundColor:[UIColor colorWithRed:188/255.0f green:155/255.0f blue:211/255.0f alpha:0.6f]];

    [button setTitle:@"Sign Up" forState:UIControlStateNormal];

    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // title color
    [button addTarget:self action:@selector(method:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

  // Button Two
    UIButton* button1 = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height-50, self.view.frame.size.width/2 , 50.0)];

   [button1 setBackgroundColor:[UIColor colorWithRed:188/255.0f green:155/255.0f blue:211/255.0f alpha:0.6f]];
    [button1 setTitle:@"Sign In" forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(method:) forControlEvents:UIControlEventTouchUpInside];

    [button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // title color
    [self.view addSubview:button1];
    // Border color for one button
    UIView *leftBorder = [[UIView alloc] initWithFrame:CGRectMake(0, 1, 1, button.frame.size.height)];
    leftBorder.backgroundColor = [UIColor colorWithRed:237/255.0f green:211/255.0f blue:246/255.0f alpha:0.6f];
    [button1 addSubview:leftBorder];

}

为什么它对景观不起作用。请帮帮我,因为它很好用。对于横向,它不工作。

它在横向中不工作,因为当我们旋转到横向时,按钮和图像视图(正如您在代码中定位的那样)位于屏幕底部下方。

您必须实现自动布局。它将解决这个问题。请避免硬编码的立场,因为这将造成问题的用户界面。如果你想硬编码点,然后使你的应用程序在纵向模式或横向模式


在自动布局中,也可以通过编程方式设置约束。只需检查哪个对您来说是可行的并实施它。

您需要1)在interface builder中创建此视图并添加一些约束,2)以编程方式添加约束,或者3)如果您反对使用自动布局,你可以检测方向变化并重新分配对象的帧以反映方向现在我在故事板中添加了uimage…当我再次打开我的1.png图像时,它已完全抓取,看起来不像portraint中的那样。虽然我的布通一点也没有显示出来,但它已经消失了,没有任何可能制作图像gud以及肖像和风景模式是的。使用布局约束而不是通过设置框架来定位它们。确定。现在我有两个设置图像,正如我在代码11.jpg,s2.jpg中提到的……现在我需要使用这两个图像来绘制肖像。和a1.jpg,a2.jpg图像的景观。你能给我解释一些代码示例吗that@user5513630你的问题是“为什么它不适合景观”,我回答了这个问题。如果你有一个新问题,问一个新问题。