iOS development--hover button

Source: Internet
Author: User

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

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.