0

I'm trying to create an interface like this

enter image description here

Where I have a piece of torn paper with drop shadow that sits below the nav bar but above my tableview.

I use the following code in my tableview controller

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.view addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed: @"ripped-paper"]]];
}

This works fine except the ripper paper scrolls with the table view. I require it to stay fixed under the navbar.

Any ideas?

4

2 回答 2

3

在 iOS 6 中,您可以只使用shadowImage.UINavigationBar

UIImage *image = [[image imageNamed:@"tornPaper"] resizableImageWithCapInsets:UIEdgeInsetsMake(/* Your insets here */)];
self.navigationItem.navigationBar.shadowImage = image;
于 2013-01-20T13:20:49.763 回答
0

您可以尝试将图像添加到表视图控制器self.view.superview

    [self.view.superview addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed: @"ripped-paper"]]];

不过,您应该在 中执行此viewDidAppear操作(否则 self.view.superview 将不会设置)。

这可能还需要更改框架/中心,或多或少像这样:

  UIImageView* rippedView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"ripped-paper"]];
  rippedView.center = <SET CENTER HERE>;
  [self.view.superview addSubview:rippedView];

但最终它将在很大程度上取决于您的视图层次结构。

编辑:

对于您的自动旋转问题,请尝试设置视图 autoresizingMaks

rippedView.autoresizingMaks = UIViewAutoresizingNone;

看看情况是否有所改善。这样,图像视图不应在旋转时调整大小。(另外:你在轮换方法中做了什么吗?)

于 2013-01-20T10:55:29.617 回答