简体   繁体   English

swift 无法显示 imageview 底部的视图

[英]swift cannot show the view at bottom of imageview

i'm trying to show a layout at from the bottom of an imageview to a predefined height.我试图显示从 imageview 底部到预定义高度的布局。 Unfortunately its shown at the top, not at the bottom.不幸的是,它显示在顶部,而不是底部。 This is my code i have tried:这是我尝试过的代码:

   var frm: CGRect = firstImageOverlay.frame
          frm.origin.x = frm.origin.x
          frm.origin.y = frm.origin.y
          frm.size.width = frm.size.width
          frm.size.height = frm.size.height
          firstImageOverlay.frame = frm
              UIView.animate(withDuration: 0.5, animations: {

                self.progressA.frame =   CGRect(x: frm.origin.x, y: frm.origin.y, width: frm.size.width,   height: self.firstImageOverlay.frame.height*CGFloat(0.4))

          })

and here is the result of this code:这是这段代码的结果: 在此处输入图像描述

the light gray part shows the layout at the left imageview.浅灰色部分显示左侧 imageview 的布局。 this should be shown from the bottom till the defined height这应该从底部显示到定义的高度

iOS uses a reflected cartesian coordinate system with 0,0 in the top right and positive y pointing down and positive x pointing right, so when you draw at x: frm.origin.x, y: frm.origin.y you are saying draw from the top left down to the width and height. iOS 使用反射笛卡尔坐标系,右上角为 0,0,正 y 指向下方,正 x 指向右侧,因此当您在x: frm.origin.x, y: frm.origin.y处绘制时,您是在说绘制从左上角到宽度和高度。

You need to adjust your y coordinate down:您需要向下调整 y 坐标:

self.progressA.frame = CGRect(x: frm.origin.x, y: frm.origin.y + self.firstImageOverlay.frame.height*CGFloat(0.6), width: frm.size.width,   height: self.firstImageOverlay.frame.height*CGFloat(0.4))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM