简体   繁体   English

如何在单击按钮时获取UIImageView的Height,Width,X和Y并将其传递给Other ViewController?

[英]How to Get Height, Width , X and Y of UIImageView on Button click and pass it to Other ViewController?

I'm creating an iOS app(objective c) and in this app I'm setting UIImageview (movable) on UIView (like Sticker). 我正在创建一个iOS应用(目标c),在此应用中,我在UIView (如Sticker)上设置了UIImageview (可移动)。 What I want to do next is when User click on button that time a new ViewController will open and that time UIImageview should be on same position(same height & width) like it's last position, height and width on previous ViewController . 我接下来要做的是,当用户单击按钮时,将打开一个新的ViewController并且该时间UIImageview应该位于相同的位置(相同的高度和宽度),如上一个ViewController的最后一个位置,高度和宽度。 But I don't know how to save position of UIImageview and use it on other ViewController . 但是我不知道如何保存UIImageview位置并在其他ViewController上使用它。 I know how to use properties from other ViewController but not getting any idea of this specific one. 我知道如何使用其他ViewController属性,但不了解这一特定属性。

Write below code in button action method: 在按钮操作方法中编写以下代码:

// Convert the co-ordinates of the view into the window co-ordinate space

   CGRect frame = [yourImgView.superview convertRect:yourImgView.frame toView:self.view];

Now, frame will be your UIImageview frame in your full viewController view, which you can pass to next viewController and use there. 现在, frame将成为整个viewController视图中的UIImageview框架,您可以将其传递到下一个viewController并在其中使用。

I Think You just need to pass the Frame of the image view before you create the new controller as property in the controller to set new the image view with that frame. 我认为您只需要传递图像视图的框架,然后在控制器中创建新的控制器作为属性,以使用该框架设置新的图像视图即可。

ViewController1 : ViewController1:

let imageViewFrame = yourimageView.frame

Viewcontroller2 : Viewcontroller2:

var imageFrame : CGRect?

Viewcontroller2.imageFrame =  imageViewFrame

newImageView.frame = imageFrame

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

相关问题 获取 UIButtons 的 Size (x, y, width, height) - Get Size (x, y, width, height) of UIButtons 如何在 UIImageView 中获得 UIImage 的 x 和 y position? - How to get x and y position of UIImage in UIImageView? 我如何通过 x 和 y 轴以及屏幕的高度和宽度在 swift 中以编程方式截取屏幕截图 - How can i pass both x and y axis along with height and width of Screen to take screenshot programmatically in swift 如何检测UIImageView的宽度和高度 - How to detect the width and height of a UIImageView 如何使按钮单击从UIView到ViewController? - How to get button click from UIView to ViewController? 如何使用自动布局获取UIView的x,y,宽度,高度 - How to get x, y, width, height of UIView which is using auto layout 如何在视图自动调整后获得CGRect值x,y,width,height? - How can i get CGRect values x,y,width,height after view is being autoresized? 单击按钮时如何设置 viewController 高度? - how can set viewController height when I click the button? 如何使用触摸UIImageView转到其他ViewController? - How to make a UIImageView with touch to go to other ViewController? UIImageView在旋转时会改变其宽度和高度,如何获得原始高度和宽度的正常状态? - UIImageView on rotating changes it width and height, how to get original height and width of normal state?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM