【问题标题】:UIImageView: full screen imageUIImageView:全屏图片
【发布时间】:2011-01-16 18:42:51
【问题描述】:

我想在 iPhone 上查看全屏图像。多少 像素我要设置吗? iphone 3 的宽度和高度不同, 4?

我的源代码:

NSString *filePath = [[NSBundle mainBundle] pathForResource:theProduct.image ofType:@"png"]; 
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:filePath]];
img.frame = CGRectMake(0.0, 0.0, ?, ?);
[self.view addSubview:img];

我应该用什么来代替问号?

非常感谢, 斯特凡诺

【问题讨论】:

    标签: iphone ios


    【解决方案1】:

    尝试将 UIImageView 的框架设置为[[UIScreen mainScreen] applicationFrame]

    这会将 UIImageView 设置为使用应用程序可用的所有空间,不包括状态栏(如果可见)。

    【讨论】:

    【解决方案2】:

    您应该将其设置为旧 iPhone 的尺寸:320 x 480 像素。然后 iPhone 4 将把它加倍以适应屏幕。如果您不想看到像素化,则需要另外一张 640 x 960 的 @2x 图像。

    【讨论】:

      【解决方案3】:

      问题已经回答(移除状态栏后使用 320 x 480 或 320 x 460)。

      作为解决类似问题的一种方法:在 Xcode 中将 UIImageView 放到 xib 中;适当调整它的大小,然后在右窗格中显示“大小检查器”(右侧的第二个选项卡)。它给出了框架矩形的宽度和高度。如果您不想缩放图像(或者更确切地说,如果您想要 1:1 的比例),请使用此宽度和高度作为图像的大小。此外(如上所述)使用双分辨率图像@2x 进行视网膜显示。

      【讨论】:

        【解决方案4】:

        这是一个非常古老的线程,所以只需更新约束是如何完成的。

        imageView?.translatesAutoresizingMaskIntoConstraints = false
        imageView?.contentMode = .scaleAspectFit
        view.backgroundColor=UIColor.blue
        view.addSubview(self.imageView!)
        
            let height = NSLayoutConstraint(item: imageView!, attribute: .height, relatedBy: .equal, toItem: view, attribute: .height, multiplier: 1, constant: 0)
            let width = NSLayoutConstraint(item: imageView!, attribute: .width, relatedBy: .equal, toItem: view, attribute: .width, multiplier: 1, constant: 0)
            view.addConstraints([height, width])
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-01-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多