iphone - Manually passing touches Began to a newly created instance -
i want object created when touch uiview. want new object able moved without finger having raised. tried passing touched event new object doesn't work.
is there way it?
you'll have derive subclass of uiview, serve holderview newly generated views. also, once new view generated, new view move along finger if not raised.
following code it, tweak later per needs:
@interface holderview : uiview @property(nonatomic,retain)uiview *newview; @end @implementation holderview - (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) { // initialization code } return self; } -(void)touchesbegan:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [touches anyobject]; cgpoint touchpoint = [touch locationinview:self]; if (cgrectcontainspoint(self.bounds, touchpoint)) { cgrect r = cgrectmake(touchpoint.x-50, touchpoint.y-50, 100, 100); self.newview = [[[uiview alloc] initwithframe:r]autorelease]; self.newview.backgroundcolor= [uicolor cyancolor]; [self addsubview:self.newview]; } } -(void)touchesmoved:(nsset *)touches withevent:(uievent *)event { if (self.newview!=nil) { uitouch *touch = [touches anyobject]; cgpoint touchpoint = [touch locationinview:self]; self.newview.center = touchpoint; } } @end
Comments
Post a Comment