android底部弹出拍照,Android 实现IOS选择拍照相册底部弹出的实例

Android 实现IOS选择拍照相册底部弹出的实例

效果图

2127b5ec0df0fcf9b0c47be6957ec3de.png

1. AndroidStudio使用

dependencies {

compile 'com.guoqi.widget:actionsheet:1.0'

}

2. 使用

//1.实现接口

implements ActionSheet.OnActionSheetSelected

//2.在某个点击事件中添加:

ActionSheet.showSheet(this, this, null);

//3.然后重写点击方法:

@Override

public void onClick(int whichButton) {

switch (whichButton) {

case ActionSheet.CHOOSE_PICTURE:

//相册

choosePic();

break;

case ActionSheet.TAKE_PICTURE:

//拍照

takePic();

break;

case ActionSheet.CANCEL:

//取消

break;

}

}

//加入自己的逻辑

public void takePic(){

String state = Environment.getExternalStorageState();

if (state.equals(Environment.MEDIA_MOUNTED)) {

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

File outDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

if (!outDir.exists()) {

outDir.mkdirs();

}

File outFile = new File(outDir, System.currentTimeMillis() + ".jpg");

picPath = outFile.getAbsolutePath();

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outFile));

intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

startActivityForResult(intent, ActionSheet.TAKE_PICTURE);

} else {

Toast.makeText(this, "请确认已经插入SD卡", Toast.LENGTH_SHORT).show();

}

}

//加入自己的逻辑

public void choosePic(){

Intent openAlbumIntent = new Intent(Intent.ACTION_PICK);

openAlbumIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");

startActivityForResult(openAlbumIntent, ActionSheet.CHOOSE_PICTURE);

}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持,如有疑问请留言或者到本站社区交流讨论,大家共同进步!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS的开发中,使用Swift可以实现底部弹出视图。以下是一个简单的实现方式: 首先,需要创建一个底部弹出视图的ViewController。可以在Storyboard中创建一个新的ViewController,并设置其底部约束为屏幕底部,高度为底部弹出视图的高度。可以在该ViewController中添加需要显示的内容,比如按钮、标签等。 然后,在需要弹出底部视图的地方,可以通过 present 方法来显示这个ViewController。可以在当前的ViewController中添加一个按钮,当点击该按钮时,调用如下代码来显示底部弹出视图: ```swift // 创建底部弹出视图的ViewController let bottomViewController = storyboard?.instantiateViewController(withIdentifier: "BottomViewController") as! BottomViewController // 设置底部弹出视图的 ModalPresentationStyle 为 .overCurrentContext,使得弹出视图会覆盖当前视图 bottomViewController.modalPresentationStyle = .overCurrentContext // 设置底部弹出视图的 TransitioningDelegate;通过实现相关代理方法来自定义弹出视图的动画效果 bottomViewController.transitioningDelegate = self // 弹出底部视图 present(bottomViewController, animated: true, completion: nil) ``` 在当前ViewController中,需要增加一个扩展来实现底部弹出视图的自定义动画: ```swift extension ViewController: UIViewControllerTransitioningDelegate { // 返回自定义的动画控制器对象 func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { return BottomViewAnimator(isPresenting: true) } // 返回自定义的动画控制器对象 func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { return BottomViewAnimator(isPresenting: false) } } ``` 在自定义动画控制器中,可以实现底部弹出视图的动画效果。可以通过使用 UIView 的动画方法来实现位移、透明度等动画效果。 最后,需要创建一个自定义的 Animator 类,实现 UIViewControllerAnimatedTransitioning 协议的相关代理方法来控制动画的展示和隐藏。 通过上述步骤,即可完成iOS底部弹出视图的实现
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值