0
我試圖添加按鈕滾動視圖內與中心約束, 約束工作,但滾動不靈滾動卡住, 任何人都可以幫助我在哪裏出錯,添加約束滾動後無法正常工作
-(void)viewDidLoad{
scrllview = [[UIScrollView alloc] initWithFrame:
[[UIScreen mainScreen] applicationFrame]];
scrllview.backgroundColor = [UIColor orangeColor];
self.view=scrllview;
[scrllview setContentSize:CGSizeMake(300, 1000)];
submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
[submitButton setTitle:@"connect" forState:UIControlStateNormal];
[submitButton.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:14.0]];
[submitButton addTarget:self
action:@selector(myMethod:)
forControlEvents:UIControlEventTouchUpInside];
submitButton.backgroundColor = [UIColor blackColor];
submitButton.translatesAutoresizingMaskIntoConstraints = NO ;
[scrllview addSubview:submitButton];
NSLayoutConstraint *constraint = [NSLayoutConstraint
constraintWithItem:submitButton
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:scrllview
attribute:NSLayoutAttributeCenterX
multiplier:1.0f
constant:0.0f];
[scrllview addConstraint:constraint];
constraint = [NSLayoutConstraint
constraintWithItem:submitButton
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:scrllview
attribute:NSLayoutAttributeCenterY
multiplier:1.0f
constant:0.0f];
[scrllview addConstraint:constraint];
}
THX重播......你可以建議我任何例子或鏈接,因爲去年5小時我已經在做這個,但仍然沒有落實。 – 2014-09-06 13:16:56
我沒有在網上找到任何示例或鏈接。但我確定,它會像我說的那樣工作。我在其中一個產品中實施,所以我不能共享代碼。你能寄給我一些不起作用的示例代碼嗎?我會修復它並向你發送更新。 – 2014-09-06 13:38:23
我在scrollview中只使用了一個按鈕,並給了scrollview.plz的包含大小的編輯並使上面的代碼正確。 – 2014-09-06 13:46:24