mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 22:51:53 +08:00
Added location_in
This commit is contained in:
@@ -37,5 +37,20 @@ module RubyMotionQuery
|
||||
self
|
||||
end
|
||||
|
||||
# @return [Array] or [CGSize]
|
||||
def location_in_root_view
|
||||
self.location_in(self.root_view)
|
||||
end
|
||||
|
||||
# @return [Array] or [CGSize]
|
||||
def location_in(view)
|
||||
out = []
|
||||
selected.each do |selected_view|
|
||||
out << selected_view.convertRect(selected_view.bounds, toView: view).origin
|
||||
end
|
||||
out = out.first if out.length == 1
|
||||
out
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -59,4 +59,20 @@ describe 'position' do
|
||||
view.origin.y.should == 90
|
||||
end
|
||||
|
||||
it 'should give location of a view within the root view' do
|
||||
view = @vc.rmq.append(UIView).move(l: 10, t: 20, w: 30, h: 40).get
|
||||
@vc.rmq(view).location_in_root_view.should == CGPoint.new(10, 20)
|
||||
|
||||
view_2 = @vc.rmq(view).append(UIView).move(l: 10, t: 20, w: 5, h: 5).get
|
||||
view_2.origin.should == CGPoint.new(10, 20)
|
||||
@vc.rmq(view_2).location_in_root_view.should == CGPoint.new(20, 40)
|
||||
end
|
||||
|
||||
it 'should give location of a views (as an array) within the root view' do
|
||||
view = @vc.rmq.append(UIView).move(l: 10, t: 20, w: 30, h: 40).get
|
||||
view_2 = @vc.rmq(view).append(UIView).move(l: 10, t: 20, w: 5, h: 5).get
|
||||
|
||||
@vc.rmq(view, view_2).location_in_root_view.should == [CGPoint.new(10, 20),CGPoint.new(20, 40)]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user