簡體   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?

我正在創建一個iOS應用(目標c),在此應用中,我在UIView (如Sticker)上設置了UIImageview (可移動)。 我接下來要做的是,當用戶單擊按鈕時,將打開一個新的ViewController並且該時間UIImageview應該位於相同的位置(相同的高度和寬度),如上一個ViewController的最后一個位置,高度和寬度。 但是我不知道如何保存UIImageview位置並在其他ViewController上使用它。 我知道如何使用其他ViewController屬性,但不了解這一特定屬性。

在按鈕操作方法中編寫以下代碼:

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

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

現在, frame將成為整個viewController視圖中的UIImageview框架,您可以將其傳遞到下一個viewController並在其中使用。

我認為您只需要傳遞圖像視圖的框架,然后在控制器中創建新的控制器作為屬性,以使用該框架設置新的圖像視圖即可。

ViewController1:

let imageViewFrame = yourimageView.frame

Viewcontroller2:

var imageFrame : CGRect?

Viewcontroller2.imageFrame =  imageViewFrame

newImageView.frame = imageFrame

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM