should this code work? if there don't appear to be any errors i'm concerned it may be a bug, but i can't be sure. :-/
On Thu, Jun 11, 2009 at 7:15 AM, Chunk 1978<chunk1...@gmail.com> wrote: > while dragging (touching) a view, i'm trying to anchor the view in the > center of the screen and resize the view's width and height based on > the drag, but it's flashes all crazy and i can't figure out why it's > doing so. i think it has to do with the resetting of the origin > because if i set the origin of the view to a static location in the > (void)touchesMoved method, it works fine, but since the drag resizes > the view, it also (is suppose to) changes it's origin. i've been in > front of this for 4 hours with no luck. please help. > > -=-=-=-=-=--=- > - (void)viewDidLoad > { > CGRect fullScreenRect = [[UIScreen mainScreen] bounds]; > > UIView *aView = [[UIView alloc] initWithFrame:fullScreenRect]; > aView.backgroundColor = [UIColor redColor]; > self.background = aView; > [aView release]; > > CGRect aFrame = CGRectMake(0, 0, 50, 50); > aFrame.origin = CGPointMake(CGRectGetMidX(fullScreenRect) - > CGRectGetMidX(aFrame), CGRectGetMidY(fullScreenRect) - > CGRectGetMidY(aFrame)); > > UIView *aBoxView = [[UIView alloc] initWithFrame:aFrame]; > aBoxView.backgroundColor = [UIColor whiteColor]; > self.boxView = aBoxView; > [aBoxView release]; > > [self.view insertSubview:background atIndex:0]; > [self.view insertSubview:boxView atIndex:1]; > > [super viewDidLoad]; > } > > > - (void)dealloc > { > [background release]; > [boxView release]; > [super dealloc]; > } > > > #pragma mark Touch Methods > > - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event > { > CGPoint point = [[touches anyObject] locationInView:self.view]; > firstTouchPoint = point; > } > > - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event > { > CGRect fullScreenRect = [[UIScreen mainScreen] bounds]; > > CGPoint point = [[touches anyObject] locationInView:self.view]; > CGRect boxFrame = boxView.frame; > > boxFrame.size.width += point.x - firstTouchPoint.x; > boxFrame.size.height += point.y - firstTouchPoint.y; > boxFrame.origin = CGPointMake(CGRectGetMidX(fullScreenRect) - > CGRectGetMidX(boxFrame), CGRectGetMidY(fullScreenRect) - > CGRectGetMidY(boxFrame)); > > [boxView setFrame:boxFrame]; > firstTouchPoint = point; > > NSString *log = [NSString stringWithFormat:@"%f, %f", > boxFrame.origin.x, boxFrame.origin.y]; > NSLog(log); > } > > -=-=-=-=-=-=-=- > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com