0
我在同一個問題上看過很多不同的主題,似乎無法理解這裏發生了什麼。我創建了一個非常簡單和簡單的項目。我想要發生的是一組元素位於滾動視圖內部,可以正確滾動。這些元素可能包括獨立滾動(或不滾動)的UITableView。下面是我如何設置我的基本項目:關於UIScrollView和AutoLayout的困惑
在模擬器中運行,這將導致不滾動視圖。這是預料之中的,因爲所有元素都有足夠的空間。後來我改變的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
任何幫助將不勝感激。
謝謝!我把所有的UI元素(按鈕,表格)放在一個'UIView'中,它是'UIScrollView'的子視圖。沒有任何額外的代碼,一切都很好。 – Alex 2013-03-06 15:37:26