蓝懿 iOS 技术交流和心得分享 11.21

 今天又到了练习日    我们复习了一下从相册中选取图片的方法,通过UIImagePickerController创建出来的页面中有两个协议分别是: UINavigationControllerDelegate和UIImagePickerControllerDelegate

一、UINavigationControllerDelegate是相册默认的系统页面导航器,其中方法中有;

1、将要展示viewController,方法中包含了两个对象UINavigationController和UIViewController;UIViewController就是你点击后将要进入的下一个页面,可以在此页面添加一些自己想要展示的东西(如在其中添加view等,viewController.viewaddSubview:v);UINavigationController创建的navigationController中有装有控制所有页面的一个数组(navigationController.viewControllers.count),可以根据页面在此数组中的位置,来对相应页面进行处理;

-(void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated;

2、已经展示viewController

-(void)navigationController:(UINavigationController*)navigationController didShowViewController:(UIViewController*)viewController animated:(BOOL)animated;

二、UIImagePickerControllerDelegate其中有两个方法:

1、选择完成,但如果调用此方法需要自己写跳出去的方法,此方法中的info控制有所选择的图片模式和图片,

有默认图片:UIImagePickerControllerOriginalImage;

可编辑图片:UIImagePickerControllerEditedImage;

选择后需要一个UIImage接收,UIImage * image = info[UIImagePickerControllerOriginalImage],

-(void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info;

 

2、取消选择:

-(void)imagePickerControllerDidCancel:(UIImagePickerController*)picker;

从相册获取图片进行编辑

 

1、搭建界面,添加按钮进行关联

2、从点击按钮跳转到相册的界面

3、选择将要跳转下一页面

4、已经完成选择图片

 

@property (nonatomic, strong)UIScrollView *sv;

@property (nonatomic, strong)NSMutableArray *seletedIVs;

@end

 

@implementation ViewController

- (IBAction)clicked:(id)sender {

    

     self.seletedIVs = [NSMutableArray array];

    

    UIImagePickerController *ipc = [[UIImagePickerController alloc]init];

    ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    ipc.delegate = self;

    //是否允许编辑

//    ipc.allowsEditing = YES;

    [self presentViewController:ipc animated:YES completion:nil];

    

    

    

}

- (void)viewDidLoad {

    [super viewDidLoad];

    

   

    

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

    

    NSLog(@"%@",UIImagePickerControllerOriginalImage);

    NSLog(@"%@",@"UIImagePickerControllerOriginalImage");

    

    UIImage *image = info[UIImagePickerControllerOriginalImage];

//    通过数组计数 让图片的x轴和数组的数量建立关系

    UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(self.seletedIVs.count*80, 0, 80, 80)];

    iv.image = image;

    [self.sv addSubview:iv];

    //打开交互

    iv.userInteractionEnabled = YES;

//    往图片中添加删除按钮

    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(60, 0, 20, 20)];

    [btn setTitle:@"X" forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];

    [iv addSubview:btn];

    

    

    [self.seletedIVs addObject:iv];

    

    [self.sv setContentSize:CGSizeMake(self.seletedIVs.count*80, 0)];

    

//    [self dismissViewControllerAnimated:YES completion:nil];

    

}

 

-(void)deleteAction:(UIButton *)btn{

    //拿到按钮所在的图片

    UIImageView *iv = (UIImageView *)btn.superview;

    //从数组中删除

    [self.seletedIVs removeObject:iv];

    // 从界面中删除

    [iv removeFromSuperview];

    

    for (int i=0; i<<span se-mark="1">self.seletedIVs.count; i++) {

        UIImageView *iv = self.seletedIVs[i];

        [UIView animateWithDuration:.5 animations:^{

            iv.frame = CGRectMake(i*80, 0, 80, 80);

        }];

        

    }

    

    

    

    

    

}

 

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated{

    

    if (navigationController.viewControllers.count==2) {

        UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 567, 375, 100)];

        v.backgroundColor = [UIColor redColor];

        [viewController.view addSubview:v];

        

        self.sv = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 375, 80)];

        self.sv.backgroundColor = [UIColor blueColor];

        [v addSubview:self.sv];

        

        //添加返回按钮

        UIButton *doneBtn = [[UIButton alloc]initWithFrame:CGRectMake(295, 0, 80, 20)];

        [doneBtn setTitle:@"Done" forState:UIControlStateNormal];

        [doneBtn addTarget:self action:@selector(finishAction:) forControlEvents:UIControlEventTouchUpInside];

        [v addSubview:doneBtn];

    }

    

   

    

    

    

}

 

-(void)finishAction:(UIButton*)btn{

    

    [self dismissViewControllerAnimated:YES completion:nil];

}

学习ios  重要还是要理清楚思路  在做或者看老师代码的时候 自己多想想为什么  不要自己看着就抄       另外还是要推荐一下 蓝懿IOS这个培训机构  和刘国斌老师刘国斌老师还是很有名气的,听朋友说刘老师成立了蓝懿iOS,,老师讲课方式很独特,能够尽量让每个人都能弄明白,有的比较难懂的地方,如果有的地方还是不懂得话,老师会换个其它方法再讲解,这对于我们这些学习iOS的同学是非常好的,多种方式的讲解会理解得更全面,这个必须得给个赞,嘻嘻,还有就是这里的学习环境很好,很安静,可以很安心的学习,安静的环境是学习的基础,小班讲课,每个班20几个学生,学习氛围非常好,每天都学到9点多才离开教室,练习的时间很充裕,而且如果在练习的过程中有什么困难,随时可以向老师求助,不像其它机构,通过视频教学,有的甚至学完之后都看不到讲师本人,问点问题都不方便,这就是蓝懿与其它机构的区别,相信在刘国斌老师的细心指导下,每个蓝懿学员都能找到满意的工作,加油!

                                                                  写博客第四十二天;

                                                                              QQ:565803433​


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值