Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iphone中将UIButton和UIImageView从一个位置移动到另一个位置?_Iphone - Fatal编程技术网

如何在iphone中将UIButton和UIImageView从一个位置移动到另一个位置?

如何在iphone中将UIButton和UIImageView从一个位置移动到另一个位置?,iphone,Iphone,如何在单击按钮时自动将UIButton和UImageView从一个位置移动到另一个位置。我还在scrollview中以编程方式创建了UIButton和UIImageView。但是我想当我点击按钮时,另一个UIImage和一个按钮移动到指定的位置 这是我的密码 if (i==0) { bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)]; bgImage.image = [UIImage

如何在单击按钮时自动将UIButton和UImageView从一个位置移动到另一个位置。我还在scrollview中以编程方式创建了UIButton和UIImageView。但是我想当我点击按钮时,另一个UIImage和一个按钮移动到指定的位置

这是我的密码

if (i==0)
{
    bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
    bgImage.image = [UIImage imageNamed:@"iphone.png"];
    [self.view addSubview:bgImage];
    [scrollview addSubview:bgImage];

    myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
    [myButton setTitle:@"Delete" forState:UIControlStateNormal];
    [myButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:myButton];
    [scrollview addSubview:myButton];
    x=x+100;
}
if (i==1) 
{
    bgImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
    bgImage1.image = [UIImage imageNamed:@"iphone.png"];
    [self.view addSubview:bgImage1];
    [scrollview addSubview:bgImage1];

    UIButton *myButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton1.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
    [myButton1 setTitle:@"Delete" forState:UIControlStateNormal];
    [myButton1 addTarget:self action:@selector(buttonClicked1) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:myButton1];
    [scrollview addSubview:myButton1];
    x=x+100;
}

- (void)buttonClicked1
{
    [bgImage removeFromSuperview];
    [bgImage release];
    bgImage=nil;
    myButton.enabled=NO;
    myButton.hidden=YES;
}
当我单击按钮Clicked1按钮时,bgImage和myButton将被移除,我希望bgImage1和myButton1在不做任何修改的情况下移动到这些位置

如何做到这一点。有人给我密码吗。我不能移动它。如何做到这一点。请帮帮我


提前感谢。

更改按钮单击中的框架。在-voidbuttonClicked1方法中执行此操作

bgImage1.frame=CGRectMake(20,30+x,100,100);
myButton1.frame = CGRectMake(120, 65+x, 70, 30);

- (void)buttonClicked1
{
bgImage1.frame=bgImage.frame;
    myButton1.frame = myButton.frame;
[bgImage removeFromSuperview];
[bgImage release];
bgImage=nil;
    myButton.enabled=NO;
myButton.hidden=YES;
}