Project need to create a hover button, I think the light to create a button can not slide a little bit less optimization, I tried to do a free to drag the hover button, I hope you can support more.
-(void) viewdidload{//create hover button Self.editeventsbutton=[uibutton Buttonwithtype:uibuttontypecustom]; Self.editeventsbutton.frame=cgrectmake (0, 0, 60, 60); [Self.editeventsbutton setbackgroundimage:[uiimage imagenamed:@ "Ask the Doctor"] forstate:uicontrolstatenormal]; [Self.editeventsbutton addtarget:self Action: @selector (gotoeditevents) forControlEvents: UIControlEventTouchUpInside]; Self.window=[[uiwindow Alloc] Initwithframe:cgrectmake (ScreenWidth-55, Screenheight-75-cgrectgetheight ( Self.chartView.frame), 60, 60)]; self.window.windowlevel=uiwindowlevelalert+1; Self.window.backgroundcolor=[uicolor Clearcolor]; self.window.layer.cornerradius=20; Self.window.layer.maskstobounds=yes; [Self.window AddSubview:self.editEventsButton]; [Self.window makekeyandvisible]; Put a drag gesture to change the position of the control uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] initwithtarget:self action:@ Selector (changepostion:)]; [Self.editeventsbutton Addgesturerecognizer:pan]; [Self charts]; [Self tabartool];} Gesture Event--change position-(void) Changepostion: (Uipangesturerecognizer *) pan{cgpoint point = [Pan TranslationInView:self.window]; CGFloat width = [UIScreen mainscreen].bounds.size.width; CGFloat height = [UIScreen mainscreen].bounds.size.height; CGRect originalframe = self.window.frame; if (originalframe.origin.x >= 0 && originalframe.origin.x+originalframe.size.width <= width) {origin Alframe.origin.x + = Point.x; } if (originalframe.origin.y >= 0 && originalframe.origin.y+originalframe.size.height <= height) { ORIGINALFRAME.ORIGIN.Y + = Point.y; } self.window.frame = Originalframe; [Pan Settranslation:cgpointzero InView:self.view]; if (pan.state = = Uigesturerecognizerstatebegan) {_editeventsbutton.enabled = NO; }else if (pan.state = = uigesturerecognizerstatechanged) {} else {CGRect frame = Self.window.fra Me Whether the record is out of bounds BOOL IsoveR = NO; if (frame.origin.x < 0) {frame.origin.x = 0; Isover = YES; } else if (Frame.origin.x+frame.size.width > width) {frame.origin.x = Width-frame.size.width; Isover = YES; } if (Frame.origin.y < 0) {frame.origin.y = 0; Isover = YES; } else if (Frame.origin.y+frame.size.height > height) {frame.origin.y = Height-frame.size.height; Isover = YES; } if (isover) {[UIView animatewithduration:0.3 animations:^{self.window.frame = frame; }]; } _editeventsbutton.enabled = YES; }}
iOS development--hover button