In an iPhone app few "letter tiles" can be dragged around:
Dragging and displaying larger image and fonts are implemented in Tile.m:
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
[_normal setHidden:YES];
[_dragged setHidden:NO];
[_letter setFont:[UIFont systemFontOfSize:60]];
[_value setFont:[UIFont systemFontOfSize:20]];
[self.superview bringSubviewToFront:self];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
CGPoint previous = [touch previousLocationInView:self];
self.frame = CGRectOffset(self.frame,
(location.x - previous.x),
(location.y - previous.y));
}
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
[_normal setHidden:NO];
[_dragged setHidden:YES];
[_letter setFont:[UIFont systemFontOfSize:36]];
[_value setFont:[UIFont systemFontOfSize:16]];
}
This works quite well except for the smaller UILabel
in the bottom right corner (which should display an integer number - the "value" of a letter).
I have tried enabling Autolayout and adding constraints... and also disabling Autolayout in Tile.xib
(here fullscreen):
but couldn't find a satisfactory solution yet (the adjusted position doesn't have to be scientifically exact).
As an iOS programming newbie I am not sure of the options I have, can anybody please advise how to fix it best?
Like aligning the baseline of the value
label to the bottom line of the letter
label + ensure they just touch each other (and not intersect) - is that possible?