在xcode中的自定义类方法调用中动态创建UIImageViews [英] dynamically creating UIImageViews in a custom class method call in xcode
问题描述
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],位置)){
onePieceCopy.center =位置;
[self带上SubviewToFront:onePieceCopy];
}
[onePieceCopy版本];
此代码在switch语句中,该语句在将触摸注册到指定UIImageView的框架内时调用的方法中。
理想的结果是系统与地图编辑器不同,在该系统中,您可以将零件从暂存区域拖到地图上(如果有任何意义的话)。 o这或我如何更好地获得所需结果的代码
WWDC 2011 (必须是注册开发人员)。观看会话104-高级滚动视图技术。在大约40分钟时,他们可以很好地拾取和放置uiimage。
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.
这篇关于在xcode中的自定义类方法调用中动态创建UIImageViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!