ios - Why a subView won't stay in the parent frame? -
i have view , inside there's uiimage
. image isn't static , can move around if drag finger around (using drag events) problem picture moves outside of uiview
frame. what's appropriate way keep inside parent frame bounds?
--uiviewa
--------uiviewb
--------------uiimage
--------------uibutton
i want keep uiimage inside uiviewb
- (ibaction)mybuttonsingletap:(uibutton *)sender { imdragging = yes; [_mybutton addtarget:self action:@selector(dragbegan:withevent:) forcontrolevents: uicontroleventtouchdown]; } - (ibaction)mybuttondraginside:(uibutton *)sender { [_mybutton addtarget:self action:@selector(draging:withevent:) forcontrolevents: uicontroleventtouchdraginside]; } - (void)dragbegan:(uicontrol *)c withevent:ev { uitouch *touch = [[ev alltouches] anyobject]; startingtouchpoint = [touch locationinview:self.view]; } - (void)draging:(uicontrol *)c withevent:ev { uitouch *touch = [[ev alltouches] anyobject]; currenttouchpoint = [touch locationinview:self.view]; _movingpic.frame = cgrectmake(currenttouchpoint.x, currenttouchpoint.y, 28, 23); }
you need check location of view during dragging.
at point setting frame of image depending on user's drag direction, etc...
during should have logic check like...
if new location x value less 0 set new location x = 0. if new location x value plus image width greater view width set new location x = view width - image width.
etc...
then use new location point move image to.
Comments
Post a Comment