다음 코드를 작성했지만 작동하지 않습니다. 사진이 나타납니다하지만 난 그것을이프로그래밍 방식으로 uiimageview 이동
UIImageView *oneselement = [[UIImageView alloc] initWithFrame:self.view.frame];
oneselement = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1el.png"]];
oneselement.frame = CGRectMake(0, 0, 122, 122);
[self.view addSubview:oneselement];
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if([touch view]==oneselement)
{
CGPoint location = [touch locationInView:self.view];
oneselement.center=location;
}}
내가 볼 수있는 사진을 추가로 이동하고 다음 코드
.H
@interface ViewController : UIViewController
{
IBOutlet UIImageView *oneEl;
}
@property (nonatomic,retain) IBOutlet UIImageView *oneEl;
하는 .m
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if([touch view]==oneEl)
{
CGPoint location = [touch locationInView:self.view];
oneEl.center=location;
}
}
을 썼다 그리고 수 없습니다 공장! uiimageview에서 프로그래밍 방식으로 생성 한 프로그램은 어떻게 움직일 수 있습니까?
있는 NSMutableArray
self.elements=[myElements getElements];
imagesElements = [[NSMutableArray alloc]init];
for(ElemetsList *item in self.elements)
{
UIImageView *oneelement = [[UIImageView alloc] initWithImage:[UIImage imageNamed:item.imgElement]];
oneelement.frame = CGRectMake(item.positionX, item.positionY, item.width, item.height);
oneelement.userInteractionEnabled=YES;
[imagesElements addObject:oneelement];
}
for(UIImageView *img in imagesElements)
[self.view addSubview:img];
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
for(UIImageView *img in imagesElements)
{
if([self view] == img)
{
CGPoint location = [touch locationInView:self.view];
img.center=location;
}
}
}
이미지를 이동하거나 이미지를 회전 하시겠습니까? – Hiren
코드에 메모리 누수가 있습니다. 어레이에 요소를 추가 한 후 oneelement를 릴리스해야합니다. – tikhop