我有一个UIImage视图,使用AutoLayout和约束设置。 我使用适当的方法将图像适配到ImageView中。
有没有一种方法可以将UIImageView适配到实际显示的UIImage?基本上我想做类似这样的事情
总之:在使用AutoLayout和Aspect fit放置后,如何知道我的imageView的绝对原点?
self.selectPhoto.contentMode = UIViewContentModeScaleAspectFit;
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom relatedBy:0 toItem:self.selectPhoto attribute:NSLayoutAttributeTop multiplier:1 constant:-10];
NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:self.selectPhoto attribute:NSLayoutAttributeBottom relatedBy:0 toItem:self.caption attribute:NSLayoutAttributeTop multiplier:1 constant:-35];
[self.view addConstraint:topConstraint];
[self.view addConstraint:bottomConstraint];
self.selectPhoto.image= existingImage;
这个代码运行得非常好。因为UIImageView是使用AutoLayout设置的,UIImage是使用Aspect Fit显示的,所以我不知道图像的确切框架。我希望图像的左上角在图像视图中的位置为0,0,因为我有另一个较小的图像可以移动到它的上面。
-(void) handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
self.itemToEdit.stickerLocation= recognizer.view.frame;
NSLog(@"The location of the sticker is %f and y is %f", recognizer.view.frame.origin.x, recognizer.view.frame.origin.y);
}
有没有一种方法可以将UIImageView适配到实际显示的UIImage?基本上我想做类似这样的事情
self.selectPhoto.frame = self.selectPhoto.image.frame
但我不能这样做。总之:在使用AutoLayout和Aspect fit放置后,如何知道我的imageView的绝对原点?