Привет у меня есть код, который выглядит следующим образомiphone ориентация не работает
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
username = [[UILabel alloc]initWithFrame:CGRectMake(53,115, 83, 21)];
username.text = @"Username";
[username setFont:[UIFont fontWithName:@"Arial" size:14]];
password = [[UILabel alloc]initWithFrame:CGRectMake(53,188, 75, 21)];
password.text = @"Password";
[password setFont:[UIFont fontWithName:@"Arial" size:14]];
txtusername = [[UITextField alloc]initWithFrame:CGRectMake(42, 144, 233, 31)];
[txtusername setBorderStyle:UITextBorderStyleRoundedRect];
[txtusername setPlaceholder:@"Username"];
[txtusername setAutocorrectionType:UITextAutocorrectionTypeNo];
txtusername.delegate = self;
txtusername.returnKeyType = UIReturnKeyDone;
txtpassword = [[UITextField alloc]initWithFrame:CGRectMake(42, 217, 233, 31)];
[txtpassword setBorderStyle:UITextBorderStyleRoundedRect];
[txtpassword setPlaceholder:@"Password"];
[txtpassword setAutocorrectionType:UITextAutocorrectionTypeNo];
txtpassword.delegate = self;
txtpassword.returnKeyType = UIReturnKeyDone;
loginbutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[loginbutton setFrame:CGRectMake(110, 269, 124, 26)];
[loginbutton setTitle:@"Login" forState:UIControlStateNormal];
}
return self;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation currentOrientation = [[UIDevice currentDevice]orientation];
switch (currentOrientation)
{
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
username.center = CGPointMake(157, 71);
password.center = CGPointMake(157,144);
txtusername.center = CGPointMake(146,100);
txtpassword.center = CGPointMake(120,172);
loginbutton.center = CGPointMake(214,225);
break;
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
username.bounds = CGRectMake(53, 115, 83, 21);
//username.center = CGPointMake(53, 115);
password.bounds = CGRectMake(53, 188, 75, 21);
//password.center = CGPointMake(53,188);
txtusername.center = CGPointMake(42,144);
txtpassword.center = CGPointMake(42,217);
loginbutton.center = CGPointMake(110,269);
break;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return YES;
}
Теперь то, что, как представляется, проблема заключается в том, что интерфейс не получает ориентированный как это слишком, компоненты не приходят к координаты, как я их дал, когда я поворачиваю оборудование iPhone влево и вправо, они не приходят в эти координаты. Когда мой просмотр загружает все в порядке, но когда я поворачиваю свой взгляд, я получаю эту ошибку. Пожалуйста, помогите мне, ребята Спасибо
Вы пытались проверить, какое значение вы получаете от currentOrientation? Раньше у меня были ошибки с [[UIDevice currentDevice]), и я нашел, что лучше использовать [self interfaceOrientation], предполагая, что self является UIViewController (или подклассом). – Altealice
Я заменил строку IInterfaceOrientation currentOrientation = [[UIDevice currentDevice] ориентация]; с UIInterfaceOrientation currentOrientation = [self interfaceOrientation]; но использование не по-прежнему не в состоянии это сделать ... – Radix