我认为我不太明白如何使用RubyMotion在屏幕上显示图像。我现在要做的就是让我们的校园地图显示在屏幕上。以下是我现在对特定视图控制器的代码:
class MapDisplayController < UIViewController
def initWithNibName(name, bundle: bundle)
super
self
end
def viewDidLoad
self.title = "Campus Map"
# Initialize an image view with an image of the map from a file.
@map_view = UIImageView.alloc.initWithImage(UIImage.imageNamed('campus.jpg'))
@map_view.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2)
# Set some basic accessibility properties.
@map_view.accessibilityLabel = "RVH Campus Map"
@map_view.userInteractionEnabled = true
self.view.addSubview @map_view
end
end
除了缺少图片之外,视图本身加载OK。我误解了如何初始化它吗?我的init
函数丢失了吗?我应该使用viewDidAppear
吗?