2016-09-25 4 views
0

私はiPhone 4または4用に作られた古いアプリを持っています。 私はそれを少し変更して、iPadを含むすべてのデバイスに適合するアプリとしてリリースしたいと思います。 私は既にコードを微調整していますので、すべてのデバイスで動作しますが、iPhone上で実行すると、4秒後にはアプリが上下にカットされます。 問題は、アプリのUIがコードで書かれており、StoryBoardをまったく使用していないことです。 UIのコード:iPhone 4アプリをすべてのiOSサイズに合わせるにはどうすればいいですか?

- (void)viewDidLoad { 
[super viewDidLoad]; 

self.screenHeight = [UIScreen mainScreen].bounds.size.height; 

UIImage *background = [UIImage imageNamed:@"bg"]; 

self.backgroundImageView = [[UIImageView alloc] initWithImage:background]; 
self.backgroundImageView.contentMode = UIViewContentModeScaleAspectFill; 
[self.view addSubview:self.backgroundImageView]; 

self.blurredImageView = [[UIImageView alloc] init]; 
self.blurredImageView.contentMode = UIViewContentModeScaleAspectFill; 
self.blurredImageView.alpha = 0; 
[self.blurredImageView setImageToBlur:background blurRadius:10 completionBlock:nil]; 
[self.view addSubview:self.blurredImageView]; 

self.tableView = [[UITableView alloc] init]; 
self.tableView.backgroundColor = [UIColor clearColor]; 
self.tableView.delegate = self; 
self.tableView.dataSource = self; 
self.tableView.separatorColor = [UIColor colorWithWhite:1 alpha:0.2]; 
self.tableView.pagingEnabled = YES; 
[self.view addSubview:self.tableView]; 

CGRect headerFrame = [UIScreen mainScreen].bounds; 
CGFloat inset = 20; 
CGFloat temperatureHeight = 110; 
CGFloat hiloHeight = 40; 
CGFloat iconHeight = 30; 
CGRect hiloFrame = CGRectMake(inset, headerFrame.size.height - hiloHeight, headerFrame.size.width - 2*inset, hiloHeight); 
CGRect temperatureFrame = CGRectMake(inset, headerFrame.size.height - temperatureHeight - hiloHeight, headerFrame.size.width - 2*inset, temperatureHeight); 
CGRect iconFrame = CGRectMake(inset, temperatureFrame.origin.y - iconHeight, iconHeight, iconHeight); 
CGRect conditionsFrame = iconFrame; 
// make the conditions text a little smaller than the view 
// and to the right of our icon 
conditionsFrame.size.width = self.view.bounds.size.width - 2*inset - iconHeight - 10; 
conditionsFrame.origin.x = iconFrame.origin.x + iconHeight + 10; 

UIView *header = [[UIView alloc] initWithFrame:headerFrame]; 
header.backgroundColor = [UIColor clearColor]; 
self.tableView.tableHeaderView = header; 

// bottom left 
UILabel *temperatureLabel = [[UILabel alloc] initWithFrame:temperatureFrame]; 
temperatureLabel.backgroundColor = [UIColor clearColor]; 
temperatureLabel.textColor = [UIColor whiteColor]; 
temperatureLabel.text = @"0°"; 
temperatureLabel.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:120]; 
[header addSubview:temperatureLabel]; 

// bottom left 
UILabel *hiloLabel = [[UILabel alloc] initWithFrame:hiloFrame]; 
hiloLabel.backgroundColor = [UIColor clearColor]; 
hiloLabel.textColor = [UIColor whiteColor]; 
hiloLabel.text = @"0°/0°"; 
hiloLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:28]; 
[header addSubview:hiloLabel]; 

// top 
UILabel *cityLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, 30)]; 
cityLabel.backgroundColor = [UIColor clearColor]; 
cityLabel.textColor = [UIColor whiteColor]; 
cityLabel.text = @"Loading..."; 
cityLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:18]; 
cityLabel.textAlignment = NSTextAlignmentCenter; 
[header addSubview:cityLabel]; 

UILabel *conditionsLabel = [[UILabel alloc] initWithFrame:conditionsFrame]; 
conditionsLabel.backgroundColor = [UIColor clearColor]; 
conditionsLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:18]; 
conditionsLabel.textColor = [UIColor whiteColor]; 
[header addSubview:conditionsLabel]; 

// bottom left 
UIImageView *iconView = [[UIImageView alloc] initWithFrame:iconFrame]; 
iconView.contentMode = UIViewContentModeScaleAspectFit; 
iconView.backgroundColor = [UIColor clearColor]; 
[header addSubview:iconView]; 

[[RACObserve([WXManager sharedManager], currentCondition) 
    deliverOn:RACScheduler.mainThreadScheduler] 
subscribeNext:^(WXCondition *newCondition) { 
    temperatureLabel.text = [NSString stringWithFormat:@"%.0f°",newCondition.temperature.floatValue]; 
    conditionsLabel.text = [newCondition.condition capitalizedString]; 
    cityLabel.text = [newCondition.locationName capitalizedString]; 

    iconView.image = [UIImage imageNamed:[newCondition imageName]]; 
}]; 

RAC(hiloLabel, text) = [[RACSignal combineLatest:@[ 
                RACObserve([WXManager sharedManager], currentCondition.tempHigh), 
                RACObserve([WXManager sharedManager], currentCondition.tempLow)] 
              reduce:^(NSNumber *hi, NSNumber *low) { 
               return [NSString stringWithFormat:@"%.0f°/%.0f°",hi.floatValue,low.floatValue]; 
              }] 
         deliverOn:RACScheduler.mainThreadScheduler]; 

[[RACObserve([WXManager sharedManager], hourlyForecast) 
    deliverOn:RACScheduler.mainThreadScheduler] 
subscribeNext:^(NSArray *newForecast) { 
    [self.tableView reloadData]; 
}]; 

[[RACObserve([WXManager sharedManager], dailyForecast) 
    deliverOn:RACScheduler.mainThreadScheduler] 
subscribeNext:^(NSArray *newForecast) { 
    [self.tableView reloadData]; 
}]; 

[[WXManager sharedManager] findCurrentLocation]; 

}

は、あなたがこれで私を助けることができます事前に感謝を願っています!

答えて

1

アプリはあなたがすべてのデバイスサイズのために適切なサイズの打ち上げ画面を使用する必要があります

トップにカットし、下

されます。今日最も簡単な方法は、LaunchScreenストーリーボードです。新しいプロジェクトを作成すると、そのプロジェクトの設定方法が表示されます。

+0

こんにちは、返信ありがとうございます。 プロジェクトにLaunchScreen.storyboardファイルを追加しました。新しい空のプロジェクトからコピーしました。画面はまだカットされています。私は今何をすることができますか?それを機能させるために何かを変更する必要がありますか? –

+0

私はそれがどのように構成されているかを見ました。方法がわからない場合は、コードを新しいプロジェクトにコピーする方がよいでしょう。新しいプロジェクトは、起動画面のストーリーボードを自動的に使用します。 – matt

+0

問題は、プロジェクトが多くのcocoapodsフレームワークを使用していることです。私は新しいプロジェクトにコピーしようとしましたが、それはちょうど仕事をしません。私はLaunchScreen.storyboardを新しいプロジェクトからコピーしました。このファイルと別の新しいファイルとの間に何か違うものがあるかどうかを確認しようとしましたが、違いは見られませんでした。私に何ができる? –

関連する問題