#在蓝懿学习iOS的日子 #day22

Source: Internet
Author: User

Get pictures from albums for editing

1, build the interface, add buttons to associate

2, from the click button to jump to the album Interface

3. Select going to jump to next page

4. You have finished selecting a picture

@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;

// whether to allow editing

ipc.allowsediting = YES;

[self presentviewcontroller: IPC animated:YES completion: Nil];

}

-(void) viewdidload {

[Super viewdidload];

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

//Dispose of any resources, can be recreated.

}

-(void) Imagepickercontroller: (uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo :(nsdictionary *) info{

NSLog(@ "%@",uiimagepickercontrolleroriginalimage);

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

UIImage *image = info[uiimagepickercontrolleroriginalimage];

Create a relationship between the X- axis and the number of groups of a picture by array Count

uiimageview *iv = [[uiimageview alloc]initwithframe:cgrectmake( self. Seletedivs. Count*, 0, (+ )];

iv. image = image;

[self. SV addsubview: iv];

// open interaction

iv. userinteractionenabled = YES;

Add a Delete button to a picture

UIButton *btn = [[UIButton alloc]initwithframe:cgrectmake( 0, a )];

[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*, 0)];

[Self dismissviewcontrolleranimated:yes completion:nil];

}

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

// get the picture where the button is located

uiimageview *iv = (uiimageview *) btn. Superview;

// Remove from array

[self. Seletedivs removeobject: iv];

// Remove from interface

[IV Removefromsuperview];

for (int i=0; i<self. Seletedivs. Count; i++) {

uiimageview *iv = self. Seletedivs[i];

[UIView animatewithduration:. 5 animations: ^{

iv. frame = cgrectmake(i*, 0, N);

}];

}

}

-(void) Navigationcontroller: (uinavigationcontroller *) Navigationcontroller Willshowviewcontroller: (uiviewcontroller *) Viewcontroller animated: (BOOL) animated{

if (Navigationcontroller. Viewcontrollers. Count= =2) {

UIView *v = [[UIView alloc]initwithframe:cgrectmake(0, 567 , 375, +)];

V.backgroundcolor = [uicolor redcolor];

[Viewcontroller. View addsubview: v];

self. SV = [[uiscrollview alloc]initwithframe:cgrectmake(0, 375 )];

self. SV. BackgroundColor = [uicolor bluecolor];

[v addsubview:self. SV];

// Add back button

UIButton *donebtn = [[UIButton alloc]initwithframe:cgrectmake(295 , 0, + )];

[Donebtn settitle:@ "Done" forstate:uicontrolstatenormal];

[Donebtn addTarget:self action:@selector(finishaction:) forcontrolevents:uicontroleventtouchupinside];

[v addsubview:d onebtn];

}

}

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

[self dismissviewcontrolleranimated:YES completion:nil];

}

#在蓝懿学习iOS的日子 #day22

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.