标签: rubymotion

如何将此Objective C重写为RubyMotion?

在目标C中,可以将背景图像设置为拉伸的png,如下所示:

button = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 300, 44)];
[button setTitle: @"Tap me" forState: UIControlStateNormal];
[button setBackgroundImage:[[UIImage imageNamed: @"greenButton.png"]
                                 stretchableImageWithLeftCapWidth:8.0f
                                 topCapHeight:0.0f]
                       forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)

试图将其转换为Ruby,我不断获得例外.问题是用两种方法呼吁UIImage的实例:stretchableImageWithLeftCapWidthtopCapHeight.

我试过以下无济于事:

greenImage = UIImage.imageNamed("greenButton.png")
greenImage.stretchableImageWithLeftCapWidth = 8.0
greenImage.topCapHeight = 0.0
@timerButton.setBackgroundImage(greenImage, forState: UIControlStateNormal)
Run Code Online (Sandbox Code Playgroud)

任何人都可以建议吗?

ruby ios5 rubymotion

2
推荐指数
1
解决办法
685
查看次数

RubyMotion:如何在控制台中调用函数?

我有两个控制器 - 如何从控制台调用其中的功能?

(main)>

rubymotion

2
推荐指数
2
解决办法
1127
查看次数

什么是RubyMotion必备的库?

我对RubyMotion开发比较陌生,但我已经在Objective-C中有过iOS的经验.

当我开始使用RubyMotion时,我找到了相当多的库.网络,数据存储等都有一些有用的库,但最让我困惑的是这些布局(UI)库.

有一堆,最流行的是: - SweetTea - SugarCube(不是真正的UI) - MotionKit - TeaCup - RMQ(不仅仅是UI)

我现在想要哪一个是非常有用的,哪一个我应该拒绝.我从头开始一个全新的项目,所以我很灵活选择什么,我想从最有用和最常用的工具开始,让我轻松开发iOS的布局.

你能为RubyMotion推荐一些必备的工具和库吗?

ruby ios rubymotion

2
推荐指数
1
解决办法
607
查看次数

RubyMotion >>如何发布POST?

我一直在查看RestKit和GET的工作原理

@client.get("/?amount=5", delegate:self)
Run Code Online (Sandbox Code Playgroud)

有谁知道如何发布POST并收到结果?

文档提到它看起来像这样 -

@client.post("/ask", params:@paramvar, delegate:self)
Run Code Online (Sandbox Code Playgroud)

你怎么封装@paramvar?我已经尝试过它作为数组,哈希甚至是零 - 然而,它们都没有产生任何结果.

rubymotion

1
推荐指数
1
解决办法
1032
查看次数

使用RubyMotion单击按钮时如何加载控制器?

假设我有2个控制器A和B.

在AI中有:

def viewDidLoad
  super
  button = UIButton.buttonWithType UIButtonTypeRoundedRect
  button.setTitle "Open B", forState: UIControlStateNormal
  button.addTarget(self, action: :open_b, forControlEvents: UIControlEventTouchUpInside)
  self.view.addSubview button
end

def open_b
  # ?????
end
Run Code Online (Sandbox Code Playgroud)

在BI中有另一种具有自己逻辑的视图,这并不重要.

我想在点击按钮时打开B. 我应该怎么做呢?

对于那些有iOS经验的人来说,这一定是显而易见的,但是我找不到你应该怎么做.任何指针都表示赞赏.Objectve-C中的解决方案是可以接受的,即使我更喜欢使用RubyMotion,也可以获得我的支持.

ruby iphone uiviewcontroller ios rubymotion

1
推荐指数
1
解决办法
1702
查看次数

RubyMotion用于游戏开发

RubyMotion如何适合iOS游戏开发?

我无法在文档中找到CoreAnimation主题,但我听说有人能够在RubyMotion中使用cocos-2d.

如果您有一些您愿意分享的有用信息,我将非常感谢!

ruby ios rubymotion

1
推荐指数
2
解决办法
1290
查看次数

在项目之间共享类的最佳实践

当我在RubyMotion中处理项目时,我经常想出一些我希望在项目之间共享的类的扩展.通常这些扩展很小,并没有真正详细说明.例如:时间类上的小扩展.在项目之间共享这些小扩展的好方法是什么?

ruby rubymotion

1
推荐指数
1
解决办法
149
查看次数

CALayer不透明度动画可以工作,但边界动画不起作用

我试图动画CALayer的界限,但它不起作用.这是代码:

class CircleView < UIIVew

  def initWithFrame(frame)
    super

    # determine the dimensions
    radius = (bounds.size.width < bounds.size.height ? bounds.size.width : bounds.size.height) / 2

    # create the circle layer
    @circle = CAShapeLayer.layer
    @circle.bounds = bounds
    @circle.path = UIBezierPath.bezierPathWithRoundedRect(bounds, cornerRadius: radius).CGPath

    @circle.fillColor = UIColor.blueColor.CGColor

    # add the circle to the view
    self.layer.addSublayer(@circle)

    shrink

    self
  end

  private

  # Applies the shrink animation to the provided circle layer.
  def shrink

    # determine the bounds
    old_bounds = @circle.bounds
    new_bounds = CGRectMake(old_bounds.size.width / 2, old_bounds.size.height / …
Run Code Online (Sandbox Code Playgroud)

ruby cocoa-touch core-animation ios rubymotion

1
推荐指数
1
解决办法
2563
查看次数

访问块内的变量

我正在 RubyMotion 中使用某个块,并尝试访问其中在外部声明的实例变量。事实证明我无法从内部访问该变量。我在这里缺少任何明显的解决方案吗?谢谢!

这是代码

@my_var = true

Dispatch::Queue.concurrent.async do
  # can't access @my_var here
end
Run Code Online (Sandbox Code Playgroud)

ruby block rubymotion

1
推荐指数
1
解决办法
653
查看次数

RubyMotion错误:工具'xcodebuild'需要Xcode

我使用以下方法创建了一个新的RubyMotion项目:

motion create NewMotion
Run Code Online (Sandbox Code Playgroud)

然后我安装了相关的包:

bundle install
Run Code Online (Sandbox Code Playgroud)

现在每当我运行应用程序时,我都会收到错误:

?  NewMotion  rake
/Users/info/.rvm/gems/ruby-2.0.0-p353/gems/bundler-1.6.2/lib/bundler/runtime.rb:222: warning: Insecure world writable dir /usr/local in PATH, mode 040777
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin13/rbconfig.rb:212: warning: Insecure world writable dir /usr/local in PATH, mode 040777
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/Library/RubyMotion/lib/motion/project/xcode_config.rb:87:in `xcode_version'
/Library/RubyMotion/lib/motion/project/xcode_config.rb:99:in `validate'
/Library/RubyMotion/lib/motion/project/template/ios/config.rb:85:in `validate'
/Library/RubyMotion/lib/motion/project/config.rb:115:in `setup'
/Library/RubyMotion/lib/motion/project/app.rb:66:in `config'
/Library/RubyMotion/lib/motion/project/template/ios.rb:81:in `block in <top (required)>'
/Users/info/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
/Users/info/.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => …
Run Code Online (Sandbox Code Playgroud)

rubymotion

1
推荐指数
1
解决办法
1865
查看次数