Top Layout Guide怎么设置高度吗

Top Layout Guide怎么设置高度吗,第1张

你可以在下面的代码从Java布局设置宽度和高度。 final AlertDialog alertDialog = alertDialogBuilder.create() final WindowManager.LayoutParams WMLP = alertDialog.getWindow().getAttributes() WMLP.gravity = Gravity.TOP WMLP.y = mActionBarHeight WMLP.x = getResources().getDimensionPixelSize(R.dimen.unknown_image_width) alertDialog.getWindow().setAttributes(WMLP) alertDialog.show()

在首次点击birthday button的时候动画修改根view的bounds和date picker view的top constraint,注意上移gap的计算。再次点击birthday button的时候将根view的bounds恢复到正常值,date picker view的top constraint也恢复到viewDidLoad中设置的值:

- (IBAction)didTapOnBirthdayButton:(id)sender

{

self.hasShowPickerView = !self.hasShowPickerView

if (self.hasShowPickerView) {

CGRect birthdayButtonFrame = self.birthdayButton.frame

birthdayButtonFrame = [self.view convertRect:birthdayButtonFrame fromView:self.birthdayButton.superview]

CGFloat birthdayButtonYOffset = birthdayButtonFrame.origin.y + birthdayButtonFrame.size.height

CGFloat gap = birthdayButtonYOffset - (self.view.frame.size.height - self.pickerContainerView.frame.size.height)

CGRect bounds = self.view.bounds

if (gap >0) {

bounds.origin.y = gap

} else {

gap = 0

}

[self replacePickerContainerViewTopConstraintWithConstant:birthdayButtonYOffset]

[UIView animateWithDuration:0.25 animations:^{

self.view.bounds = bounds

[self.view layoutIfNeeded]

}]

} else {

[self replacePickerContainerViewTopConstraintWithConstant:self.view.frame.size.height]

CGRect bounds = self.view.bounds

bounds.origin.y = 0

[UIView animateWithDuration:0.25 animations:^{

self.view.bounds = bounds

[self.view layoutIfNeeded]

}]

}

}

上述代码中的[self.view layoutIfNeed]去掉也是没问题的。可能比较费解的是根view.bounds.origin.y的上移gap的计算以及top constraint的constant值的计算,关键实在真正理解view的frame和bounds的意义。

选择File-->CAM,在对话框中选择丝印层,点Edit-->Layers,然后将top和silkscrenen top(底层就是bottom和silkscreen bottom)添加到右边的Selected框中,然后分别选中这两项,勾选Ref.Des选项,点OK即可。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/7954075.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-11
下一篇 2023-04-11

发表评论

登录后才能评论

评论列表(0条)

保存