UIImageView不会调整大小以匹配UIView的帧

时间:2015-06-14 23:45:11

标签: ios uiview uiimageview cgrect

我希望我的背景成为一个图像,所以在IB中我设置一个UIImageView,其约束大小与其UIView相同。但是,当我在back上选择“UINavigationBar”时,当NavControl弹出到上一个VC时,这就是它在消失之前的简要信息:{{ 0}}

也就是说,UIImageView非常大,几乎是UIView宽度的两倍,所以当它在屏幕右侧滑动时,UIImageView的图像会在最终之前拖动消失。

我也尝试过以编程方式执行此操作,但即使我将UIImageView的帧设置为CGRectMake(0, 0, 100, 100),它仍然会转到UIView的左侧,好像UIView的原点不是在左上角,而是略微偏离屏幕。这可能吗?如何制作图像以使图像适合屏幕并且不会熄灭?

如果它完全相关,我jpg使用的Images.xcassets位于UIImageView,虽然我可以在IB中选择并显示,viewDidLoad的图片为白色/ blank,所以在我的[UIImage imageNamed:@"hockeyIce.jpg"]方法中,我需要指定self.imageView.image = func screenShotMethod() { //Create the UIImage let image = view?.snapshot //Save it to the camera roll UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil) self.socialShare(sharingText: "text", sharingImage: image, sharingURL:NSURL(string: "itms-apps://itunes.apple.com/app/bars/XXXXXXXX")) } func socialShare(#sharingText: String?, sharingImage: UIImage?, sharingURL: NSURL?) { var sharingItems = [AnyObject]() if let text = sharingText { sharingItems.append(text) } if let image = sharingImage { sharingItems.append(image) } if let url = sharingURL { sharingItems.append(url) } let activityViewController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil) activityViewController.excludedActivityTypes = [UIActivityTypeCopyToPasteboard,UIActivityTypeAirDrop,UIActivityTypeAddToReadingList,UIActivityTypeAssignToContact,UIActivityTypePostToTencentWeibo,UIActivityTypePostToVimeo,UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,UIActivityTypePostToWeibo] var currentViewController:UIViewController=UIApplication.sharedApplication().keyWindow!.rootViewController! currentViewController.presentViewController(activityViewController, animated: true, completion: nil) shareButton.alpha = 1.0 }

2 个答案:

答案 0 :(得分:1)

  1. 转到 Main.storyboard
  2. 选择有问题的视图
  3. 点击属性检查器
  4. 向下滚动至查看,选择模式:缩放至

答案 1 :(得分:0)

OK, the solution was to add [self.imageView setClipsToBounds:YES] to my viewDidLoad. It turns out that this is a common problem with aspectFill.