在xcode中的自定义类方法调用中动态创建UIImageViews [英] dynamically creating UIImageViews in a custom class method call in xcode

查看:56
本文介绍了在xcode中的自定义类方法调用中动态创建UIImageViews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在另一个uiimageview的框架内注册触摸时动态创建uiimageview并将其添加到视图中。我希望它们保留在屏幕上,并在每个uiimageview的框架内注册触摸时保持可移动性。这是我现在拥有的代码,但是它不能正常工作,并且确实存在故障(即,我可以拾取一个新视图并创建它,但是随着触摸的移动,它无法正确跟随触摸:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆