问题描述 投票:0回答:1

我有一个调色板imageeview,我想根据从后台得到的x轴和y轴放置一个加号图标(imageView)。如果我得到x = 0和y = 0,那么加号的框架就会被正确放置。

x=0,y=0

对于y轴,如果我将调色板imageView的高度设置为加图标的框架的y轴,图标就不会到实际的(0,0)

x=0,y=width.

我使用的代码如下

 let cWidth = self.colorPalleteImageView.frame.size.width // 348
 let cHeight = self.colorPalleteImageView.frame.size.height // 378.5

 let imageView = UIImageView(image: appImages.roundPlusIcon.image)
 imageView.frame = CGRect(x: 0, y: cHeight, width: 22, height: 22)
 colorPalleteImageView.addSubview(imageView)

我正在用iPad 12.9英寸模拟器检查。如果我给colorPaletteImage的宽度到x轴的plusIconImageView,它不会在x轴结束,它停留在图像视图的宽度结束之前,我不知道为什么会发生,需要帮助。

ios objective-c swift uiimageview coordinates
1个回答
1
投票

你使用的是框架大小 之前 框架已经完成被自动布局设置。

我建议使用约束条件,但如果你想坚持框架坐标......

  • 添加 "圆形加号 "图标imageView中的。viewDidLoad()
  • 设置其 frame.originviewDidLayoutSubviews()viewDidAppear()

0
投票

imageView.frame = CGRect(x: cWidth, y: cHeight, width: 22, height: 22)

桅杆是。

imageView.frame = CGRect(x: 0, y: 0, width: 22, height: 22)

作为轴是。

0,0--------------------------------------------------------> x

© www.soinside.com 2019 - 2024. All rights reserved.