开发者

dynamically creating UIImageViews in a custom class method call in xcode

开发者 https://www.devze.com 2023-01-14 14:42 出处:网络
i want to dynamically create and add to the view a uiimageview when a touch is registered within the frame of another uiimageview. i want these to stay on the screen and remain moveable when a touch i

i want to dynamically create and add to the view a uiimageview when a touch is registered within the frame of another uiimageview. i want these to stay on the screen and remain moveable when a touch is registered inside the frame of each uiimageview. here is the code i have now but it doesn't quite work right and is really glitchy(i.e. i can pick up a new view and it is created but it doesn't follow the touch properly as the touch is moved:

image = [UIImage imageNamed:@"1.png"];
UIImageView *onePieceCopy = [[UIImageView alloc] initWithImage:image];
onePieceCopy.frame = CGRectMake(currentPos.x, currentPos.y, 75, 75);
[self addSubview:onePieceCopy];
if (CGRectContainsPoint([onePieceCopy frame], position)) {
    onePieceCopy.center = position;
[self bringSubviewToFront:开发者_开发百科onePieceCopy];
} 
[onePieceCopy release];

this code is in a switch statement that is in a method that is called when a touch is registered inside the frame of a designated UIImageView.

the ideal result would be a system not unlike a map editor where you drag parts from a 'staging' area and onto the map, if that makes any sense. does anyone know how to do this or how i can better my code to get the desired result


WWDC 2011 (must be a registered developer). Watch "Session 104 - Advanced Scroll View Techniques". At about minute 40 they do a nice pick and place of a uiimage.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号