Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.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 如何在没有界面生成器的情况下移动现有图像_Iphone_Xcode_Uiimageview_Move - Fatal编程技术网

Iphone 如何在没有界面生成器的情况下移动现有图像

Iphone 如何在没有界面生成器的情况下移动现有图像,iphone,xcode,uiimageview,move,Iphone,Xcode,Uiimageview,Move,我没有使用interface builder创建了多个图像。我使用了以下代码: for (Row* row in parser.rows) { CGRect IphoneFrameImageRect; IphoneFrameImageRect = CGRectMake(10, 10, 150.0f, 150.0f); UIImageView *IphoneFrame = [[UIImageView alloc] initWithFrame:Ipho

我没有使用interface builder创建了多个图像。我使用了以下代码:

for (Row* row in parser.rows) {
        CGRect IphoneFrameImageRect;
        IphoneFrameImageRect = CGRectMake(10, 10, 150.0f, 150.0f);
        UIImageView *IphoneFrame = [[UIImageView alloc] initWithFrame:IphoneFrameImageRect];
        NSString *IphoneFrameurl = [NSString stringWithFormat:@"http://some.url.com/iphone/IphoneFrame.png"];
        [IphoneFrame setImage:[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:IphoneFrameurl]]]];
        [IphoneFrame setTag:(i)];
        IphoneFrame.opaque = YES; // explicitly opaque for performance

        [self.view addSubview:IphoneFrame];
        [IphoneFrame release];
}
我需要在横向模式下将这些图像移动到其他位置。我确实标记了每幅图像,看起来我可以用这个标记重新选择图像。但是我怎样才能给图像一个新的坐标呢?我有以下代码:

-(void)positionViews {
    UIInterfaceOrientation destOrientation = self.interfaceOrientation;

    int i=4; //Picture with tag=4 for example
    UIImage *tempImage=(UIImage *)[self.view viewWithTag:(i)];

    // HOW TO MOVE ??

}
我可以使用以下代码通过按钮执行此操作:

UIButton *tempButton=(UIButton *)[self.view viewWithTag:i];
[temp setFrame:CGRectMake(x, y, X10ButtonWidth, X10ButtonHeight)];

您混淆了两种不同的事物/类别:

  • UIImage
    表示内存中的图像数据及其像素
  • ui图像视图
    表示要在屏幕上显示图像的视图
如果您更清楚,
UIImage
是指
UIImageView
什么是
NSString
是指
UILabel
。表示数据/内容的对象与可在屏幕上显示它的视图不同

因此,当您想使用设置的标记检索imageview时,您可以检索一个视图,尤其是一个
UIImageView
,以了解重要的内容,而不是
UIImage


将您的cast更改为
UIImageView
,您将能够在其上调用
setFrame:
,方法与调用
UIButton
的方法相同(因为
setFrame:
UIView
类的一种方法,
UIImageView
UIButton
都是
UIView
的子类)

或者甚至不执行任何强制转换,因为
viewWithTag:
返回一个
UIView
,如果您只想更改帧,这就是您所需要的:无论它是基本
UIView
还是具体地说是
UIImageView
或任何类型的视图,如果您只想更改
frame
属性,都无所谓,因为这是泛型
UIView
类的一个属性,可以应用于任何
UIView
,无论它是
UIView
的任何特定子类

UIView *tempImageView = [self.view viewWithTag:(i)];
[tempImageView setFrame:...];

tempImage不应该是UIImageView吗?如果将其更改为UIImageView,您应该能够像使用按钮一样调用setFrame。
UIView *tempImageView = [self.view viewWithTag:(i)];
[tempImageView setFrame:...];