这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,28 @@ end

---

### Delegate callbacks

These methods (if implemented in your `MapScreen`) will be called when the corresponding `MKMapViewDelegate` method is invoked:

```ruby
def will_change_region(animated)
# Do something when the region will change
# The animated parameter is optional so you can also define it is simply:
# def will_change_region
# end
end

def on_change_region(animated)
# Do something when the region changed
# The animated parameter is optional so you can also define it is simply:
# def on_change_region
# end
end
```

---

### CocoaTouch Property Convenience Methods

`MKMapView` contains multiple property setters and getters that can be accessed in a more ruby-like syntax:
Expand Down
11 changes: 11 additions & 0 deletions app/test_screens/test_map_screen.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
class TestMapScreen < PM::MapScreen
attr_accessor :infinite_loop_points, :request_complete, :action_called
attr_accessor :got_will_change_region, :got_on_change_region

start_position latitude: 35.090648651123, longitude: -82.965972900391, radius: 4
title "Gorges State Park, NC"
tap_to_add length: 1.5, annotation: {animates_drop: false, title: "A new park?"}

def on_load
@action_called = false
@got_will_change_region = false
@got_on_change_region = false
end

def promotion_annotation_data
Expand Down Expand Up @@ -54,4 +57,12 @@ def my_action
@action_called = true
end

def will_change_region
@got_will_change_region = true
end

def on_change_region
@got_on_change_region = true
end

end
16 changes: 16 additions & 0 deletions lib/ProMotion/map/map_screen_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,22 @@ def mapView(map_view, didUpdateUserLocation:userLocation)
end
end

def mapView(map_view, regionWillChangeAnimated:animated)
if self.respond_to?("will_change_region:")
will_change_region(animated)
elsif self.respond_to?(:will_change_region)
will_change_region
end
end

def mapView(map_view, regionDidChangeAnimated:animated)
if self.respond_to?("on_change_region:")
on_change_region(animated)
elsif self.respond_to?(:on_change_region)
on_change_region
end
end

########## Cocoa touch Ruby counterparts #################

def type
Expand Down
14 changes: 14 additions & 0 deletions spec/func_map_screen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,18 @@ def add_image_annotation
@placemark = nil
end
end

it "should call will_change_region" do
map_screen.on_load
map_screen.got_will_change_region.should == false
map_screen.mapView(map_screen.map, regionWillChangeAnimated: true)
map_screen.got_will_change_region.should == true
end

it "should call on_change_region" do
map_screen.on_load
map_screen.got_on_change_region.should == false
map_screen.mapView(map_screen.map, regionDidChangeAnimated: true)
map_screen.got_on_change_region.should == true
end
end