相关疑难解决方法(0)

使用约束移动视图

我的视图控制器中有几个视图,当检测到向下滑动时向下移动,然后在检测到向下滑动时向下移动.我通过使用CGRectOffset调整y原点来强制移动视图.我现在已经对IB的观点应用了约束,我不确定最好的方法是移动视图,以便它们最终在iphone 5,6和6+上的正确位置.

目前我正在做这样的事情:

[self.view layoutIfNeeded];

    self.panFrameVerticalConstraint.constant = self.panFrameVerticalConstraint.constant +338;

    [UIView animateWithDuration:5
                     animations:^{
                         [self.view layoutIfNeeded];
                     }];
Run Code Online (Sandbox Code Playgroud)

使用比率更改常量是否更好?因此,对于上面的约束,而不是使用338,这样做会更好:

    self.panFrameVerticalConstraint.constant = self.panFrameVerticalConstraint.constant + (self.panView.frame.size.height/1.680);

    //self.panView.frame.size.height = 568
    //(568/1.680) = 338
Run Code Online (Sandbox Code Playgroud)

objective-c ios autolayout nslayoutconstraint swift

4
推荐指数
1
解决办法
1万
查看次数

UIImageView上的宽度和高度NSLayoutConstraints不起作用

我在View Controller的UIImgeView实例上设置.Width和.Top NSLayoutConstraints updateViewConstraints()。在XCode可视调试器中,我可以看到约束实际上已设置,但是由于某些原因,约束没有被使用(?),它们显示为un(内容大小),并且显示为灰色。当我使用NSLog输出约束时,我也可以看到它们已设置,但是以某种方式图像保持原始大小...这是什么意思?

constraints in parent: [<NSLayoutConstraint:0x7b379590 UIImageView:0x7af897b0.centerX == UIView:0x7b37d2e0.centerX>, 
                        <NSLayoutConstraint:0x7b36e3d0 V:|-(0)-[UIImageView:0x7af897b0]   (Names: '|':UIView:0x7b37d2e0 )>]
constraints in view: [<NSContentSizeLayoutConstraint:0x7ae892b0 H:[UIImageView:0x7af897b0(301)] Hug:251 CompressionResistance:750>, 
                      <NSContentSizeLayoutConstraint:0x7ae834e0 V:[UIImageView:0x7af897b0(365)] Hug:251 CompressionResistance:750>]
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

设置约束的代码:

/// Image view with the character + ellipse
@IBOutlet weak var charImageView: UIImageView!

override func updateViewConstraints() {
      super.updateViewConstraints()
      charImageView.widthLayoutConstraint?.constant = 301.0
      charImageView.heightLayoutConstraint?.constant = 365.0
}
Run Code Online (Sandbox Code Playgroud)

我用来获取扩展名widthLayoutConstraintheightLayoutConstraint

extension UIView{
  /**
   Gets the width layout constraint defined as the NSLayoutConstraint whose first item is self and first attribute is Height …
Run Code Online (Sandbox Code Playgroud)

layout constraints interface-builder ios swift

1
推荐指数
1
解决办法
2457
查看次数