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