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