我正在将现有的iOS应用程序从Objective-C转换为RubyMotion.
我遇到的第一个主要缺陷是AppDelegate类引用了应用程序中定义的其他类.
由于这些是在AppDelegate类之后编译的,因此会引发异常:
2012-06-20 13:38:03.088 myApp[3349:f803] *** Terminating app due to uncaught exception 'NameError', reason: 'uninitialized constant AppDelegate::User (NameError)
Run Code Online (Sandbox Code Playgroud)
我可以通过在我的Rakefile中明确声明应该在AppDelegate类之前编译User类来解决这个问题,但是当你处理一个有30多个类的应用程序时,这几乎不是最佳解决方案,其中许多类是相互引用的.
有没有更好的方法来解决RubyMotion中的这个问题?
当我在./resources目录中使用子文件夹时,我无法访问它们.正确组织资源的正确方法是什么?
我正在使用RubyMotion来构建iOS应用程序.
我正在使用Facebook和Parse.
我已经设置了三个不同的Facebook和Parse应用程序.
我应该如何设置RubyMotion以为每个环境使用每个应用程序的正确凭据?使用yml文件是否正确?如果是这样我应该把它们放在哪里,我应该如何加载它们.
在rails中有像develop.rb这样的东西吗?
我正在使用Rubymotion构建一个iOS应用程序.我需要将一段Objective-c代码"转换"为Ruby.它是否正确?
最初是在Objective-c
[movieWriter setCompletionBlock:^{
[filter removeTarget:movieWriter];
[movieWriter finishRecording];
}];
Run Code Online (Sandbox Code Playgroud)
Ruby中的相同内容?:
movieWriter(setCompletionBlock:-> { filter.removeTarget(movieWriter) }, { movieWriter.finishRecording })
Run Code Online (Sandbox Code Playgroud) 我试图在我的rubymotion应用程序中使用一些CATransition常量:
transition = CATransition.animation
transition.duration = 0.4
transition.type = kCATransitionMoveIn
transition.subtype = kCATransitionFromBottom
Run Code Online (Sandbox Code Playgroud)
但我得到未定义的局部变量或方法`kCATransitionMoveIn'.我在rake文件中添加了quartzcore到框架:
app.frameworks + = ['CoreLocation','MapKit','QuartzCore']
有谁知道为什么我无法访问此常量?谢谢.
我是RubyMotion的新手,并试图了解对象初始化的工作原理.假设一个带有一个类和一个实例方法的简单类:
class Something
def self.getSomething
BubbleWrap::HTTP.post("http://example.com") do |response|
p response
end
end
def getSomething
BubbleWrap::HTTP.post("http://example.com") do |response|
p response
end
end
end
Run Code Online (Sandbox Code Playgroud)
现在,为什么以下工作:
Something.getSomething
Run Code Online (Sandbox Code Playgroud)
并且下一个片段不是,有时候(运行此片段和运行时在10次中崩溃了8次).
something = Something.new
something.getSomething
Run Code Online (Sandbox Code Playgroud)
我做错了.任何正确方向的指针?
请参阅以下代码:
def viewDidLoad
super
self.view.translatesAutoresizingMaskIntoConstraints = false
self.view.backgroundColor = UIColor.whiteColor
@start = UIButton.buttonWithType(UIButtonTypeRoundedRect).tap do |el|
el.translatesAutoresizingMaskIntoConstraints = false
el.setTitle('Start', forState:UIControlStateNormal)
el.addTarget(self, action:'toStartController', forControlEvents:UIControlEventTouchUpInside)
self.view.addSubview(el)
end
self.layout_subviews
end
def layout_subviews
metrics = { 'space' => 8 }
views_dict = {
'superview' => self.view,
'start' => @start
}
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat('H:|-[start(100)]-|',
options: NSLayoutFormatAlignAllCenterX,
metrics: metrics,
views: views_dict))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat('V:[start]-|',
options: NSLayoutFormatAlignAllBottom,
metrics: metrics,
views: views_dict))
end
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是H:|-[start(100)]-|行不通的.我想要的是一个宽度为100的按钮,以X轴为中心,并以默认边距连接到屏幕底部.一旦我删除(100)这个工作,但按钮伸展到屏幕的宽度减去默认边距.当我指定自定义宽度时,我认为自动布局系统无法确定左边距和右边距应该是什么.我收到一个Unable to simultaneously satisfy constraints.错误.我想这与破折号有关H:|-[start(100)]-|,它需要有一个流体宽度来将start元素附加到superview,而不是默认边距.
有关如何解决这个问题的任何想法?
更新(感谢ghettopia): …
autolayout rubymotion ios6 nslayoutconstraint visual-format-language
有哪些库可用于RubyMotion中的侧边栏菜单功能?

与这个应用程序设计非常相似的东西,我想知道是否可以使用RubyMotion.
希望你能帮助我.代码是Rubymotion,但我很确定这是一个iOS问题.代码很简单,希望Rubymotion不会妨碍答案.我可以阅读Obj-C,所以如果你只能用Obj-C回答,我对此很好.
我有一个UIImage对象.我正试着弄它的大小.当我执行以下操作时:
image = info.objectForKey(UIImagePickerControllerOriginalImage)
@image = UIImage.alloc.initWithCIImage(image)
puts @image.to_s
puts @image.size
puts @image.to_s
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
#<UIImage:0x9513710>
NSInvalidArgumentException: -[UIImage extent]: unrecognized selector sent to instance 0x10fb7410 (RuntimeError)
#<UIImage:0x9513710>
Run Code Online (Sandbox Code Playgroud)
我已经读过,当你得到范围错误时,它往往意味着对象已经释放并且不再在内存中但是如果我注释掉.size行,第3行仍然运行意味着它还没有被释放.
有任何想法吗?
在一台项目的另一台计算机上成功安装和使用SDK后,我很难让它在另一台工作站上运行,收到以下错误:
[!] Unable to find a specification for `Facebook-iOS-SDK`.
Run Code Online (Sandbox Code Playgroud)
SDK的版本是v3.5.1.
使用以下rakefile:
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require 'bundler'
require 'motion-cocoapods'
Bundler.require
Motion::Project::App.setup do |app|
app.name = 'FacebookApp'
app.frameworks = ["UIKit", "Foundation", 'AdSupport', 'Accounts', 'Social']
app.weak_frameworks += %w{ AdSupport Accounts Social }
app.pods do
pod 'Facebook-iOS-SDK'
end
app.device_family = :iphone
app.interface_orientations = [:portrait]
app.info_plist['FacebookAppID'] = 'xxx'
app.info_plist['URL types'] = { 'URL Schemes' => 'fb://profile/xxx'}
app.identifier = 'xxx'
end
Run Code Online (Sandbox Code Playgroud)
以下Gemfile:
# A sample Gemfile
source "https://rubygems.org"
gem "motion-cocoapods", "1.3.0.rc1" …Run Code Online (Sandbox Code Playgroud) 我有以下代码来显示一个简单的按钮:
button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
button.center = CGPointZero
button.frame = [[container.width/2-button.frame.size.width/2,150], [280,50]]
button.setTitle("Categorize New Project", forState: UIControlStateNormal)
button.addTarget(self,
action: "moveToChildView:",
forControlEvents: UIControlEventTouchUpInside)
Run Code Online (Sandbox Code Playgroud)
当我在带有6.1的模拟器iPhone视网膜(3.5英寸)中运行此应用程序时,它看起来像这样:

但是,当我在模拟器iPhone视网膜7.0中运行它时,它看起来像这样:

此代码是否需要更改才能与7.0一起使用?
我正在尝试使用 NSGradient 并将其保存为 RubyMotion 中的图像,但我无法让它工作。这是我到目前为止的代码:
gradient = NSGradient.alloc.initWithColors(colors,
atLocations: locations.to_pointer(:double),
colorSpace: NSColorSpace.genericRGBColorSpace
)
size = Size(width, height)
image = NSImage.imageWithSize(size, flipped: false, drawingHandler: lambda do |rect|
gradient.drawInRect(rect, angle: angle)
true
end)
data = image.TIFFRepresentation
data.writeToFile('output.tif', atomically: false)
Run Code Online (Sandbox Code Playgroud)
它运行没有错误,但保存的文件是空白的,没有图像数据。任何人都可以帮助我指出正确的方向吗?
rubymotion ×12
ios ×3
iphone ×2
objective-c ×2
autolayout ×1
constructor ×1
ios6 ×1
ios6.1 ×1
ios7 ×1
macos ×1
nsgradient ×1
nsimage ×1
ruby ×1
sdk ×1