【问题标题】:How to move image in background of view?如何在视图背景中移动图像?
【发布时间】:2012-12-29 11:44:15
【问题描述】:

我的应用程序有问题,我有一个可以正常工作的动态图像。 但是我的图像也在一个按钮上移动,当图像在按钮之前时我无法点击。如何确保图像在我的视图背景上移动,以便我仍然可以按下按钮。

我的图像也可以正常工作,但是当我测试应用程序时,图像有时会超出视图,我该如何防止这种情况发生?

这是运动图像的代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [[self navigationController] setNavigationBarHidden:YES animated:YES];
    [self loadImage];
    image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cow.png"]];
    image.frame =self.view.bounds;
    [[self view] addSubview:image];


    [NSTimer scheduledTimerWithTimeInterval: 3
                                     target: self
                                   selector:@selector(moveImage:)
                                   userInfo: nil repeats:YES];



}



-(void) moveImage: (NSTimer*)timer {

    CGFloat x = (CGFloat) (arc4random() % (int) self.view.bounds.size.width);
    CGFloat y = (CGFloat) (arc4random() % (int) self.view.bounds.size.height);
CGPoint pointOne=CGPointMake(x,y);
    image.center=pointOne;
}
}

【问题讨论】:

    标签: iphone ios image uiimageview


    【解决方案1】:

    viewDidLoad[[self view] addSubview:image];之后添加此代码

    [self.view sendSubviewToBack:image]; //Send image to back
    

    [self.view bringSubviewToFront:button]; //Bring button to front
    

    希望对你有帮助..

    【讨论】:

    • prateek 在我打字时回答了你也可以使用这种方法。
    【解决方案2】:

    将您的按钮视图放在前面。

    [self.view bringSubViewToFront:button.view];
    

    【讨论】:

      【解决方案3】:

      使用这些方法中的任何一种来管理视图的层次结构

      [self.view insertSubView:atIndex:]; [self.view insertSubView:belowView:]; [self.view insertSubView:aboveView:]; [self.view带来SubViewToFont:]; [self.view sendSubviewToBack:];

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-11
        • 2014-11-25
        • 1970-01-01
        • 2014-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多