开发者

iPhone - user interaction with programmatically added UIImageView

开发者 https://www.devze.com 2022-12-30 09:09 出处:网络
So I\'m trying to add UIImageViews programatically (in this case I don\'t have the option of doing it in IB) and I want to be able to refer to them and manipulate them in the -touchesBegan and -touche

So I'm trying to add UIImageViews programatically (in this case I don't have the option of doing it in IB) and I want to be able to refer to them and manipulate them in the -touchesBegan and -touchesMoved methods.

I've added the images like this:

UIImageView *newPiece = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png", [piece tag]]]];
newPiece.frame = CGRectMake(pieceX, pieceY, pieceW开发者_开发百科, pieceH);
[newPiece setCenter:CGPointMake(pieceX, pieceY)];
[newPiece setTag:[piece tag]];
[[self view] addSubview:newPiece];
[newPiece release];

And note, many of these newPiece's are added programmatically, because the method that this is in is called more than once, so the images have different centers and images and stuff, so would I need an array to hold all of them?

Thanks


NSMutableArray would probably suit your needs.


Check this very detailed post. It's precisely about handling several programatically added UIImageViews and it worked nice for me.

Create multiple views and make the touched view follow the users touch

Best luck.

0

精彩评论

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

关注公众号