私は同じ問題について多くの異なるスレッドを見回しましたが、ここで何が起こっているのか理解できないようです. 非常に基本的で単純なプロジェクトを作成しました。私がやりたいのは、適切にスクロールするスクロール ビュー内に多数の要素を配置することです。これらの要素には、独立してスクロールする (またはしない) UITableView を含めることができます。基本的なプロジェクトを設定する方法は次のとおりです。
これをシミュレーターで実行すると、スクロールしないビューになります。すべての要素に十分なスペースがあるため、これは予期されることです。次に、UIScrollView のサイズを次のように変更しました。
これをシミュレーターで実行すると、スクロールしない小さなビューになります。私はこれを正しい方法で行っていないと思います。最近試したコードは次のとおりです。
ViewController.h
@interface ViewController : UIViewController <UIScrollViewDelegate>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIButton *buttonOne;
@property (strong, nonatomic) IBOutlet UIButton *buttonTwo;
@property (strong, nonatomic) IBOutlet UIButton *buttonThree;
@property (strong, nonatomic) IBOutlet UIButton *buttonFour;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.buttonOne setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.buttonTwo setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.buttonThree setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.buttonFour setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
どんな助けでも大歓迎です。