【问题标题】:UIActivityIndicatorView in an UIScrollviewUIScrollview 中的 UIActivityIndi​​catorView
【发布时间】:2012-05-11 06:10:46
【问题描述】:

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

【问题讨论】:

  • 能否添加代码,如何定义活动指示器视图的框架?
  • 将其添加到 UIScrollView 的父级,而不是 UIScrollView 本身。 (这可能取决于父母是什么。)
  • 其实我想知道是否有任何方法可以在屏幕窗口的坐标中定位 UIActivityIndi​​catorView 而不是滚动视图。
  • Nathan S,uiscrollview的父级是窗口。
  • @luyuan - Natahn 非常正确,您需要将指示器视图添加到滚动视图的超级视图,然后将其置于前面。在这种情况下,它将始终定位在您想要的位置。

标签: iphone ios uiscrollview uiactivityindicatorview


【解决方案1】:

如果您将 UIActivityIndi​​catorView 直接添加到滚动视图,它将随滚动视图一起滚动。但是,如果您将它添加到滚动视图的父级,它将保留在它放置的位置。所以,解决办法是把它添加到滚动视图的父级中。

注意事项:

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

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

View Controller being sent a message even though it has been deallocated

【讨论】:

  • 是的。但是当滚动视图没有父视图时,我该如何解决这个问题?我把它设为“self.view = myScrollView”。
  • 我建议您添加一个高级 UIViewController 。
  • 在此处查看有关将内容直接添加到窗口的讨论:stackoverflow.com/questions/1585688/…
【解决方案2】:
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];

【讨论】:

  • "secondaryImage.layer.cornerRadius = 12;"错误消息:在转发类对象“CALayer *”中找不到属性“cornerRadius”
【解决方案3】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多