ปรับขนาด UIView จากปลายเท่านั้นโดยใช้ UIPanGestureRecognizer

ฉันมีเส้นแนวตั้ง (UIView) ซึ่งฉันต้องปรับขนาด ขณะนี้ฉันทำโดยใช้ท่าทางบีบ แต่ตอนนี้ฉันต้องทำโดยใช้ท่าทางปัดและเพิ่มหรือลดความสูงจากด้านข้างที่ฉันปัด ตัวอย่างเช่น หากฉันปัดลงจาก TOP END ของเส้น เส้นนั้นจะต้องลดขนาดลงจากด้านบนเท่านั้น ด้านล่างจะต้องยึดอยู่กับตำแหน่งเดิม ฉันจะทำอย่างไร?

ฉันยังต้องสามารถย้ายรูปภาพไปรอบๆ ได้ ซึ่งฉันได้นำไปใช้แล้วโดยใช้ UIPanGestureRecognizer ด้วยเช่นกัน

นี่คือสิ่งที่ฉันกำลังเล่นอยู่: ฉันมี UIView เล็กๆ ที่ปลายด้านบนของเส้นแนวตั้งและอีกอันอยู่ที่ปลายล่างของเส้น ฉันใช้สิ่งเหล่านี้เป็นเครื่องหมาย ตอนนี้ฉันสามารถเลื่อนเครื่องหมายด้านบนขึ้นและลงได้แล้ว ฉันต้องปรับขนาดเส้นให้มีระยะห่างระหว่างเครื่องหมายทั้งสอง และให้ปลายด้านล่างของเส้นอยู่ในตำแหน่งเดียวกับเครื่องหมายด้านล่าง

นี่คือสิ่งที่ฉันมี

func draggedViewForTopMarker(sender: UIPanGestureRecognizer) {
      //To move the top marker
        var translation = sender.translationInView(self.view)
        sender.view!.center = CGPointMake(sender.view!.center.x, sender.view!.center.y + translation.y)
        sender.setTranslation(CGPointZero, inView: self.view)
      //Find distance between the markers
        var distanceBetweenMarkers = (sender.view!.center.y + translation.y) - self.bottomMarker.center.y
        print(distanceBetweenMarkers)
        if (distanceBetweenMarkers < 0) {
            distanceBetweenMarkers = distanceBetweenMarkers*(-1)
        }
      //**TRYING** to resize the line to have the same height as the distance between the two markers AND make sure its positioned between the markers and the bottom end of the line is still in the same place as it was originally. 
        var newFrame = CGRectMake(sender.view!.center.x, distanceBetweenMarkers/2, vertical.frame.width, distanceBetweenMarkers)
        vertical.frame = newFrame
    }

ฉันก็เปิดรับแนวทางที่แตกต่างกันเช่นกัน หรือวิธีแก้ไขปัญหาที่ฉันมีด้วยวิธีนี้!

คุณสามารถดู Photo Measures Lite บน App Store เพื่อทำความเข้าใจสิ่งที่ฉันหมายถึงเมื่อฉันพูดว่า "ปรับขนาดเส้นจากด้านเดียวเท่านั้น"

ขอบคุณมาก!


person bobMarshal    schedule 18.12.2015    source แหล่งที่มา


คำตอบ (1)


แทนที่จะสร้างเฟรมใหม่ คุณก็สามารถปรับตำแหน่ง y ของเส้นให้เหมือนกับเครื่องหมายด้านบน และความสูงให้เท่ากับระยะห่างระหว่างเครื่องหมายทั้งสองได้

func draggedViewForTopMarker(sender: UIPanGestureRecognizer) {
  //To move the top marker
    var translation = sender.translationInView(self.view)
    sender.view!.center = CGPointMake(sender.view!.center.x, sender.view!.center.y + translation.y)
    sender.setTranslation(CGPointZero, inView: self.view)
  //Find distance between the markers
    var distanceBetweenMarkers = self.topMarker.frame.origin.y - self.bottomMarker.frame.origin.y
vertical.frame.origin.y = self.topMarker.frame.origin.y
vertical.frame.size.height = distanceBetweenMarkers
}

แต่การดำเนินการนี้จะใช้ได้ก็ต่อเมื่อเครื่องหมายทั้งสองและเส้นแนวตั้งเป็นมุมมองย่อยของการตรวจสอบเดียวกัน

person Gili Tiko    schedule 27.01.2016