Skip to content

Instantly share code, notes, and snippets.

@smartweb
Last active August 29, 2015 13:57
Show Gist options
  • Save smartweb/9546908 to your computer and use it in GitHub Desktop.
Save smartweb/9546908 to your computer and use it in GitHub Desktop.
点击拍照或从相册获取照片
# 需要加入BubbleWrap和Sugarcube 的Gem
def shoot
UIActionSheet.alert('', buttons: [nil, nil, '马上拍一张', '从手机相册选择', '返回']) do |pressed|
case pressed
when '马上拍一张'
BW::Device.camera.rear.picture(media_types: [:movie, :image]) do |result|
set_photo(result[:original_image])
end
when '从手机相册选择'
BW::Device.camera.any.picture(media_types: [:movie, :image]) do |result|
set_photo(result[:original_image])
end
end
end
end
def set_photo(photo)
return if photo.nil?
@photo = photo.scale_to_fill([800,800])
@small = photo.scale_to_fill([80,80])
@shoot_btn.setImage(@small, forState:UIControlStateNormal)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment