0

我有一个全屏 UIScrollView 来显示我的图像。UIActivityIndi​​catorView 被添加到 UIScrollView 中,它旋转得很好,但是当我滚动、缩放、旋转时,如何让它始终在屏幕中间旋转?

4

3 回答 3

2

如果将 UIActivityIndi​​catorView 直接添加到滚动视图中,它将随滚动视图一起滚动。但是,如果您将它添加到滚动视图的父级,它将保留在它放置的位置。因此,解决方案是将其添加到滚动视图的父级。

笔记:

我建议在你的窗口中有一个 UIViewController,然后将它们都添加到 UIViewController。

请参阅此处有关将视图直接添加到窗口的讨论:

视图控制器被发送消息,即使它已被释放

于 2012-05-11T06:24:04.447 回答
1
In ur .h file

        UIView *primaryImage;
    UIView *secondaryImage;
    UIActivityIndicatorView *indicator;

In ur .m file 


-(void)indicatorView
{
    primaryImage = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)]; 
    primaryImage.backgroundColor = [UIColor blackColor];
    primaryImage.alpha =0.5;
    //[self.view.superview insertSubview:primaryImage aboveSubview:self.view.superview];

    //[theTableView addSubview:primaryImage];
    [self.view addSubview:primaryImage];

    secondaryImage = [[UIView alloc] initWithFrame:CGRectMake(127.50,215,65,50)];
    secondaryImage.backgroundColor = [UIColor blackColor];
    secondaryImage.alpha = 0.9;
    secondaryImage.layer.cornerRadius = 12;
    [primaryImage addSubview:secondaryImage];

    indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(30, 25, 25, 25)];
    indicator.center = CGPointMake(32, 25);
    //[indicator hidesWhenStopped];
    [indicator startAnimating];
    [secondaryImage addSubview:indicator];
}



-(void)dismissCoverImageView {

    [indicator stopAnimating];
    [indicator removeFromSuperview];
    [secondaryImage removeFromSuperview];
    [primaryImage removeFromSuperview]; 
}

and after that you can call         [self indicatorView];
and [self dismissCoverImageView];
于 2012-05-11T06:38:36.663 回答
0

定义 UIScrollView 的 UIScrollViewDelegate。并在委托方法中–(void)scrollViewDidScroll:(UIScrollView *)scrollView更改 UIActivityIndi​​cator 对象的框架。

于 2012-05-11T06:28:21.700 回答