ImageView中心位于scrollView之上

时间:2013-05-29 14:13:32

标签: ios objective-c imageview scrollview

好的,我有两个UIImageViews位于UIScrollView的子视图中。我想要的是当用户在屏幕上的某个地方滚动并点击一个表格(屏幕上的一个按钮)时,会出现一个弹出窗口(UIImageview)。我想要的是图片视图位于 center 。这是我的代码:

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSLog(@"%f scrollView Last X", scrollView.contentOffset.x);
    NSLog(@"%f scrollView Last y", scrollView.contentOffset.y);

    //This is for the orders
    self.roundFrame = [[UIImageView alloc] initWithFrame:CGRectMake(190 + scrollView.contentOffset.x ,120 + scrollView.contentOffset.y, 385, 280)];
    self.roundFrame.image = [UIImage imageNamed:@"frame_round_edge.png"];
    [_roundFrame setUserInteractionEnabled:YES];

    //This is for the split Table
    self.roundFrameForSplit = [[UIImageView alloc] initWithFrame:CGRectMake(190 +  scrollView.contentOffset.x, 120 + scrollView.contentOffset.y, 370, 300)]; // 362
    self.roundFrameForSplit.image = [UIImage imageNamed:@"frame_round_edge.png"];
    [_roundFrameForSplit setUserInteractionEnabled:YES];
}

虽然发生的事情是,大多数时候它都出现在中心,但有时却不会出现在中心。我不知道如何解决这个问题。有谁知道如何解决这一问题?谢谢你的帮助!

编辑:对于今后寻找这个问题答案的人来说,就是这样。因为在我的情况下(你可能会根据你想要完成的事情而有所不同),我只是想在ipadMini屏幕的中心放置UIImageView,所以我只是有点欺骗并硬编码值(1024/2和768 / 2)。不要忘记将你的UIImageView作为子视图添加到self.View(我犯了错误并丢失了大声笑)。希望这有帮助!

3 个答案:

答案 0 :(得分:1)

scrollview 之外设置 imageview 并将其隐藏。

当您希望它显示在滚动视图上时,请提供 imageview 图片并取消隐藏。

答案 1 :(得分:0)

尝试在

中编写相同的代码
  
      
  • (void)scrollViewDidScroll:(UIScrollView *)scrollView
  •   

然后检查。

答案 2 :(得分:0)

这可能是你的主题。这样做可以在主线程上工作,如

  [self performSelectorOnMainThread:@selector(yourMethos:) withObject:YourObject waitUntilDone:NO];

我希望你理解它并且可以轻松申请。感谢

相关问题