【问题标题】:Add background to IKImageView为 IKImageView 添加背景
【发布时间】:2011-06-29 01:39:29
【问题描述】:

我想为 IKImageView 添加棋盘背景以查看透明图像。 我正在尝试将带有棋盘图像的 CALayer 设置为带有消息 setOverlay:forType

的 IKImageView
CFURLRef imageURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),(CFStringRef)@"bgImage.png", NULL, NULL);
CGImageSourceRef imageSource = CGImageSourceCreateWithURL(imageURL,NULL);
CFRelease(imageURL);
CGImageRef image = CGImageSourceCreateImageAtIndex(imageSource, 0,NULL);
CFRelease(imageSource);
CALayer *bgLayer = [[CALayer alloc] init ];
[bgLayer setContents:image ];
[ imageView setOverlay:bgLayer forType:IKOverlayTypeBackground ];

但不起作用。我在控制台中收到此消息

could not add '<CALayer: 0x101d039a0>' linkedTo 'kIKRootLayerType'

有谁知道什么是错的或任何解决方法?

谢谢

【问题讨论】:

    标签: cocoa imagekit


    【解决方案1】:

    错误消息是因为视图未附加到顶视图。

    最后我在IKImageview的NSScrollview容器中添加了棋盘格背景, 这样背景层会自动调整大小

    CALayer *layer=[[SquareBackgroundLayer alloc] init];
    [[ scrollView contentView] setLayer:layer];
    [ layer release ];
    

    我希望这对任何人都有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-30
      • 2012-06-25
      • 1970-01-01
      • 1970-01-01
      • 2019-02-28
      • 2022-01-24
      • 2016-02-21
      相关资源
      最近更新 更多