[英]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.