ios - UITextView inside the UIImageView -
i have uiimageview.if tap imageview zoom in.if click or touch anywhere inside imageview textview.so happen is,if touch bottom of imageview,textview not appear.also after touch , textview inside imageview,if touch below of imageview disappear above textview.simultaneously want save data of textview content sqlite database without using save button.i want save textview text in sqlite database should in 1 row(in textview column-text1,text2,text3).
below .h coding
#import <uikit/uikit.h> #import <quartzcore/quartzcore.h> #import <corelocation/corelocation.h> #import <addressbook/addressbook.h> #import <addressbookui/addressbookui.h> #import <sqlite3.h> #import "sqlitedbone.h" #import "locationmodel.h" #import "businessmodeone.h" @interface cameragalleryviewcontroller : uiviewcontroller<uigesturerecognizerdelegate,uiimagepickercontrollerdelegate,uitextviewdelegate,cllocationmanagerdelegate,uitextfielddelegate,uinavigationcontrollerdelegate> { sqlitedbone *manage; uiview *dynamicview; uiimageview *dynamicimg; uitextview *textview; float xvalue; float yvalue; cgfloat animateddistance; }
.m part
#import "cameragalleryviewcontroller.h" @interface cameragalleryviewcontroller () @end @implementation cameragalleryviewcontroller @synthesize cameragalleryimage,swi,textfld,locationlabel,datelabel,timelabel,locationmanager,array_image; - (void)viewdidload { [super viewdidload]; // additional setup after loading view. manage =[sqlitedbone shareone]; //[manage createdb]; [sqlitedbone createdbone]; [self tapdetected1]; //date label nsdate* date = [nsdate date]; nsdateformatter* formatterdate = [[nsdateformatter alloc] init]; [formatterdate setdateformat:@"dd-mm-yyyy"]; nsstring *strdate = [formatterdate stringfromdate:date]; datelabel.text=strdate; //time label nsdate* date1 = [nsdate date]; nsdateformatter* formattertime = [[nsdateformatter alloc] init]; [formattertime setdateformat:@"hh:mm:ss"]; nsstring* strtime = [formattertime stringfromdate:date1]; timelabel.text=strtime; array_image=[[nsmutablearray alloc]init]; [self startsignificantchangeupdates]; } - (void)viewwillappear:(bool)animated { uitapgesturerecognizer *tapgesture1 =[[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(tapdetected1)]; tapgesture1.numberoftapsrequired =1; tapgesture1.numberoftouchesrequired =1; cameragalleryimage.userinteractionenabled =yes; [cameragalleryimage addgesturerecognizer:tapgesture1]; uitapgesturerecognizer *tapgesture2 =[[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(tapdetected2)]; tapgesture2.numberoftouchesrequired=1; tapgesture2.numberoftapsrequired=1; cameragalleryimage.userinteractionenabled =yes; [cameragalleryimage addgesturerecognizer:tapgesture2]; uitapgesturerecognizer *tapgesture3 =[[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(tapdetected3)]; tapgesture3.numberoftapsrequired =1; tapgesture3.numberoftouchesrequired =1; cameragalleryimage.userinteractionenabled =yes; [cameragalleryimage addgesturerecognizer:tapgesture3]; } -(void)tapdetected1 { uiimagepickercontroller *picker =[[uiimagepickercontroller alloc]init]; picker.sourcetype =uiimagepickercontrollersourcetypephotolibrary; picker.delegate =self; [self presentviewcontroller:picker animated:no completion:nil]; } -(void)tapdetected2 { uiimagepickercontroller *picker = [[uiimagepickercontroller alloc]init]; picker.sourcetype =uiimagepickercontrollersourcetypecamera; picker.delegate =self; [self presentviewcontroller:picker animated:no completion:nil]; } -(void)tapdetected3 { //for dynamically creating view dynamicview =[[uiview alloc]initwithframe:cgrectmake(10, 100, 280, 260)]; dynamicview.backgroundcolor=[uicolor whitecolor]; [self.view addsubview:dynamicview]; //for dynamically creating imageview dynamicimg =[[uiimageview alloc]init]; dynamicimg.frame=cgrectmake(10, 100, 280, 260); [dynamicimg setuserinteractionenabled:yes]; dynamicimg.image =cameragalleryimage.image; [dynamicview addsubview:dynamicimg]; uitapgesturerecognizer *tapgesture4 =[[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(tapdetected4)]; tapgesture4.numberoftapsrequired=1; tapgesture4.numberoftouchesrequired=1; dynamicimg.userinteractionenabled =yes; [dynamicimg addgesturerecognizer:tapgesture4]; } -(void)touchesbegan:(nsset *)touches withevent:(uievent *)event { uitouch *touch =[[event alltouches]anyobject]; cgpoint touchpoint = [touch locationinview:dynamicimg]; nslog(@"touch x :%f y: :%f",touchpoint.x,touchpoint.y); xvalue =touchpoint.x; yvalue =touchpoint.y; } -(void)tapdetected4 { if (xvalue > 145.0) { xvalue = 145.00; } textview =[[uitextview alloc]initwithframe:cgrectmake(xvalue, yvalue, 130, 40)]; [textview setdelegate:self]; [[textview layer] setbordercolor:[[uicolor graycolor] cgcolor]]; [[textview layer] setborderwidth:2.3]; [[textview layer] setcornerradius:15]; [dynamicimg addsubview:textview]; } -(void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { //cameragalleryimage.image =[info objectforkey:uiimagepickercontrolleroriginalimage]; uiimage *image=[info objectforkey:@"uiimagepickercontrolleroriginalimage"]; cameragalleryimage.image=image; [array_image addobject:image]; picker.delegate =self; [picker dismissviewcontrolleranimated:no completion:nil]; } -(void)imagepickercontrollerdidcancel:(uiimagepickercontroller *)picker { [picker dismissviewcontrolleranimated:no completion:nil]; } -(void)textviewdidbeginediting:(uitextfield *)textview { cgrect textviewrect = [self.view.window convertrect:textview.bounds fromview:textview]; cgrect viewrect = [self.view.window convertrect:self.view.bounds fromview:self.view]; cgfloat midline = textviewrect.origin.y + 0.5 * textviewrect.size.height; cgfloat numerator = midline - viewrect.origin.y - minimum_scroll_fraction * viewrect.size.height; cgfloat denominator = (maximum_scroll_fraction - minimum_scroll_fraction) * viewrect.size.height; cgfloat heightfraction = numerator / denominator; if (heightfraction < 0.0) { heightfraction = 0.0; } else if (heightfraction > 1.0) { heightfraction = 1.0; } animateddistance = floor(portrait_keyboard_height * heightfraction); cgrect viewframe = self.view.frame; viewframe.origin.y -= animateddistance; [uiview beginanimations:nil context:null]; [uiview setanimationbeginsfromcurrentstate:yes]; [uiview setanimationduration:keyboard_animation_duration]; [self.view setframe:viewframe]; [uiview commitanimations]; } -(void)textviewdidendediting:(uitextfield *)textview { cgrect viewframe = self.view.frame; viewframe.origin.y += animateddistance; [uiview beginanimations:nil context:null]; [uiview setanimationbeginsfromcurrentstate:yes]; [uiview setanimationduration:keyboard_animation_duration]; [self.view setframe:viewframe]; [uiview commitanimations]; } static const cgfloat keyboard_animation_duration = 0.3; static const cgfloat minimum_scroll_fraction = 0.2; static const cgfloat maximum_scroll_fraction = 0.8; static const cgfloat portrait_keyboard_height = 216; - (bool)textview:(uitextview *)textview shouldchangetextinrange:(nsrange)range replacementtext:(nsstring *)text; { //for assigining space , length text view condition if(textview.text.length >=100) { [textview resignfirstresponder]; return no; } if([text rangeofcharacterfromset:[nscharacterset newlinecharacterset]].location == nsnotfound) { return yes; } [textview resignfirstresponder]; return no; } -(void)startsignificantchangeupdates { if ([cllocationmanager locationservicesenabled]) { if (!self.locationmanager) self.locationmanager = [[cllocationmanager alloc] init]; self.locationmanager.delegate = self; [self.locationmanager startmonitoringsignificantlocationchanges]; } } -(void)stopsignificantchangesupdates { [self.locationmanager stopupdatinglocation]; self.locationmanager = nil; } -(void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations { cllocation *location = [locations lastobject]; clgeocoder *geocoder =[[clgeocoder alloc]init]; [geocoder reversegeocodelocation:location completionhandler:^(nsarray *placemarks,nserror *error) { clplacemark *placemark = placemarks[0]; nsdictionary *addressdictionary =[placemark addressdictionary]; nsstring *city = addressdictionary[(nsstring *)kabpersonaddresscitykey]; nsstring *state = addressdictionary[(nsstring *)kabpersonaddressstatekey]; nsstring *street=addressdictionary[(nsstring *)kabpersonaddressstreetkey]; nsstring *country = placemark.country; locationlabel.text=[nsstring stringwithformat:@"%@ %@ %@ %@",street,city,state,country]; }]; [self stopsignificantchangesupdates]; } -(bool)textfieldshouldreturn:(uitextfield *)textfield { [textfield resignfirstresponder]; return yes; } - (ibaction)switchaction:(id)sender { if(swi.ison) { [self tapdetected1]; } else { [self tapdetected2]; } } -(void)preparedatabase { nsmutablearray *arraytotalimage =[[nsmutablearray alloc]init]; (uiimage *img in array_image) { nsstring *str =[businessmodeone getsavedphotopath:img]; [arraytotalimage addobject:str]; } nslog(@"%@",arraytotalimage); if ([arraytotalimage count] ==0) { businessmodeone *businessdbone = [[businessmodeone alloc]init]; businessdbone.txtfldstrone =textfld.text; businessdbone.txtviewstrone =textview.text; businessdbone.arrayone=nil; businessdbone.strlocationone=locationlabel.text; businessdbone.strdateone=datelabel.text; businessdbone.strtimeone=timelabel.text; [sqlitedbone insertdataintosqliteone:businessdbone]; } else { (int i=0; i<[arraytotalimage count]; i++) { businessmodeone *businessdbone =[[businessmodeone alloc]init]; businessdbone.txtfldstrone=textfld.text; nslog(@"the textfield == %@",businessdbone.txtfldstrone); businessdbone.txtviewstrone=textview.text; nslog(@"the textview ==%@", businessdbone.txtviewstrone); businessdbone.arrayone =[arraytotalimage objectatindex:i]; businessdbone.strlocationone=locationlabel.text; nslog(@"the location == %@",businessdbone.strlocationone); businessdbone.strdateone=datelabel.text; nslog(@"the date is== %@", businessdbone.strdateone); businessdbone.strtimeone=timelabel.text; nslog(@"the time ==%@",businessdbone.strtimeone); [sqlitedbone insertdataintosqliteone:businessdbone]; } } } -(ibaction)backbutton:(id)sender { [self.navigationcontroller poptorootviewcontrolleranimated:yes]; [self preparedatabase]; }
just replace coding
-(void)tapdetected3 { //for dynamically creating imageview dynamicimg =[[uiimageview alloc]init]; dynamicimg.frame=cgrectmake(10, 100, 280, 260); [dynamicimg setuserinteractionenabled:yes]; dynamicimg.image =cameragalleryimage.image; [self.view addsubview:dynamicimg]; //add image view self.view uitapgesturerecognizer *tapgesture4 =[[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(tapdetected4)]; tapgesture4.numberoftapsrequired=1; tapgesture4.numberoftouchesrequired=1; dynamicimg.userinteractionenabled =yes; [dynamicimg addgesturerecognizer:tapgesture4]; }
Comments
Post a Comment