Free drag slider for IOS

Source: Internet
Author: User

Completely free-drag slider

Floatviewexample

  

Code implementation:

@implementation Floatview#pragma mark-lazyload-(Uiimageview *) ImageView {if (_imageview = nil) {_imageview        = [[Uiimageview alloc]init];        _imageview.image = [UIImage imagenamed:@ "Telephone"];    _imageview.frame = Self.bounds; } return _imageview;}    -(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) Event {Uitouch *touch = [touches anyobject];    Cgpoint pt = [Touch LocationInView:self.superview];    CGRect frame = self.frame;    Position in the own view cgpoint pt = [Touch locationinview:self];    Cgpoint anchorpoint = Cgpointmake (Pt.x/self.bounds.size.width, pt.y/self.bounds.size.height);    This is set to the position is the center of the position percentage//That is, the location of the mouse self.layer.anchorPoint = Anchorpoint; Self.frame = frame;}    -(void) touchesmoved: (Nsset *) touches withevent: (Uievent *) Event {Uitouch *touch = [touches anyobject];        Cgpoint pt = [Touch LocationInView:self.superview];    Self.layer.position = pt; }-(void) touchesended: (Nsset *) touches withevent: (UIEvent *) Event {[Self limitrangeofview];} -(void) touchescancelled: (Nsset<uitouch *> *) touches withevent: (Uievent *) event {[Self limitrangeofview];}        -(void) Limitrangeofview {[UIView animatewithduration:0.3 animations:^{cgfloat padding = 1;        CGRect frame = self.frame;        if (frame.origin.x < padding) {frame.origin.x = padding;        } if (Frame.origin.y < padding) {frame.origin.y = padding; } if (Frame.origin.x > (kscreenwidth-frame.size.height-padding)) {frame.origin.x = Kscreenwidth-fram        e.size.width-padding; } if (Frame.origin.y > (kscreenheight-frame.size.height-padding)) {FRAME.ORIGIN.Y = Kscreenheight-fr        ame.size.height-padding;    } self.frame = frame; }];} @end

  

GitHub Address: Floatviewexample

Free drag slider for IOS

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.