Ich habe UIWebView und in seiner Scrollview, Ich habe eine UIImageView wie so:Swift - UIImageView Halten Sie in der gleichen Position auf drehen
self.webview.scrollView.addSubview(image)
mein Problem ist, wenn ich mein Gerät von Hoch- auf Querformat drehen die UIImageView tut nicht an der Position bleiben, die ich ursprünglich auf der ScrollView gesetzt habe, ich verstehe die Breite und Höhe des Bildschirms ändern, ich denke, was ich versuche, es zu ändern, die Position auf meinem UIImageView, so scheint es nicht geändert hat.
Ich habe diese Methode anstelle:
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
var newScrollViewFrame = webview.scrollView.frame
var newFrame = webview.frame
newFrame.size.width = size.width
newFrame.size.height = size.height
newScrollViewFrame.size.width = size.width
newScrollViewFrame.size.height = size.height
webview.frame = newFrame
webview.scrollView.frame = newScrollViewFrame
}
Der aktuelle Code in dieser Methode nur die UIWebView und seine Scroll-Ansicht Größe ändern, aber nicht die UIImageViews im Scroll
Jede Hilfe würde geschätzt.
Danke,
ich folgendes versucht:
for views in webview.scrollView.subviews
{
if(views.isKindOfClass(UIImageView))
{
views.transform = CGAffineTransformMakeRotation(CGFloat(M_PI)/2);
}
}
auf drehen
aber dies setzt auf UIImageView seitwärts
Hier ist, wie ich die Webansicht zu der Ansicht bin und fügte hinzu:
webview = UIWebView()
webview.frame = self.view.bounds
webview.scrollView.frame = webview.frame
webview.userInteractionEnabled = true
webview.scalesPageToFit = true
webview.becomeFirstResponder()
webview.delegate = self
webview.scrollView.delegate = self
self.view.addSubview(webview)
Ich habe mein Problem halb gelöst, aber folgendes tun:
Aber jetzt ist das UIWebView nicht volle Breite oder Höhe:
Ich habe das auch versucht, aber die UIImageView bleiben nicht an der gleichen Stelle.
let left = NSLayoutConstraint(item: self.webView, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1, constant: 0)
let right = NSLayoutConstraint(item: self.webView, attribute: .Right, relatedBy: .Equal, toItem: self.view, attribute: .Right, multiplier: 1, constant: 0)
let top = NSLayoutConstraint(item: self.webView, attribute: .Top, relatedBy: .Equal, toItem: self.view, attribute: .Top, multiplier: 1, constant: 0)
let bottom = NSLayoutConstraint(item: self.webView, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1, constant: 0)
NSLayoutConstraint.activateConstraints([top, bottom, left, right])
Ich habe auch versucht, Einschränkungen der UIImageView Zugabe
let stampView:StampAnnotation = StampAnnotation(imageIcon: UIImage(named: "approved.png"), location: CGPointMake(currentPoint.x, currentPoint.y))
self.webview.scrollView.addSubview(stampView)
let left = NSLayoutConstraint(item: stampView, attribute: .Left, relatedBy: .Equal, toItem: self.webview.scrollView, attribute: .Left, multiplier: 1, constant: 0)
let right = NSLayoutConstraint(item: stampView, attribute: .Right, relatedBy: .Equal, toItem: self.webview.scrollView, attribute: .Right, multiplier: 1, constant: 0)
let top = NSLayoutConstraint(item: stampView, attribute: .Top, relatedBy: .Equal, toItem: self.webview.scrollView, attribute: .Top, multiplier: 1, constant: 0)
let bottom = NSLayoutConstraint(item: stampView, attribute: .Bottom, relatedBy: .Equal, toItem: self.webview.scrollView, attribute: .Bottom, multiplier: 1, constant: 0)
NSLayoutConstraint.activateConstraints([top, bottom, left, right])
gleiche Ergebnis tritt UIImageView nicht an der gleichen Stelle bleiben.
UPDATE
Mein Webansicht:
webview = UIWebView()
webview.userInteractionEnabled = true
webview.scalesPageToFit = true
webview.becomeFirstResponder()
webview.delegate = self
webview.scrollView.delegate = self
self.view.addSubview(webview)
webview.loadRequest(NSURLRequest(URL:url))
webview.gestureRecognizers = [pinchRecognizer, panRecognizer]
webview.translatesAutoresizingMaskIntoConstraints = false
let left = NSLayoutConstraint(item: webview, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1, constant: 0)
let right = NSLayoutConstraint(item: webview, attribute: .Right, relatedBy: .Equal, toItem: self.view, attribute: .Right, multiplier: 1, constant: 0)
let top = NSLayoutConstraint(item: webview, attribute: .Top, relatedBy: .Equal, toItem: self.view, attribute: .Top, multiplier: 1, constant: 0)
let bottom = NSLayoutConstraint(item: webview, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1, constant: 0)
NSLayoutConstraint.activateConstraints([top, bottom, left, right])
UIImageView
stampView.translatesAutoresizingMaskIntoConstraints = false
let left = NSLayoutConstraint(item: stampView, attribute: .Left, relatedBy: .Equal, toItem: self.webview.scrollView, attribute: .Left, multiplier: 1, constant: 100)
let right = NSLayoutConstraint(item: stampView, attribute: .Right, relatedBy: .Equal, toItem: self.webview.scrollView, attribute: .Right, multiplier: 1, constant: 0)
let top = NSLayoutConstraint(item: stampView, attribute: .Top, relatedBy: .Equal, toItem: self.webview.scrollView, attribute: .Top, multiplier: 1, constant: 100)
let bottom = NSLayoutConstraint(item: stampView, attribute: .Bottom, relatedBy: .Equal, toItem: self.webview.scrollView, attribute: .Bottom, multiplier: 1, constant: 0)
let width = NSLayoutConstraint(item: stampView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0.1, constant: 150)
let height = NSLayoutConstraint(item: stampView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 73)
NSLayoutConstraint.activateConstraints([left, right, top, bottom, width, height])
Ich muss nur die Mathematik herauszufinden, dieses Gerät an der Position der Berührung zu haben. (In Prozent?)
Gibt es einen Grund/eine Einschränkung, das automatische Layout nicht zu verwenden? – RomOne
Nein, was soll ich tun RomOne? – user979331
Zum Beispiel könnten Sie Ihrem Bild 4 Einschränkungen hinzufügen. .centerX in Bezug auf die Webansicht, den oberen Abstand, den unteren Abstand zu anderen Ansichten in der Webansicht und dann eine proportionale Breite zur Webansicht. Denken Sie daran, dass Ihre Scrollview entsprechend ihrem Inhalt eingestellt ist, so dass Sie Constraints in einer bestimmten Weise festlegen müssen. Sie können dieses Tutorial überprüfen, um eine Idee zu haben, wie man macht http://mokagio.github.io/tech-journal/2015/06/24/ios-scroll-view-and-interface-builder.html – RomOne