【问题标题】:Xcode Button Click AlphaXcode 按钮单击 Alpha
【发布时间】:2012-02-22 12:51:03
【问题描述】:

基本上我正在尝试制作一个形状为圆形的按钮并向其添加图像。该图像是具有透明度的 png 表示球体。将它添加到自定义按钮就可以了,但它有一个问题。球体周围的透明内容也是可点击的。如何让图片的不透明区域可以点击?

【问题讨论】:

    标签: iphone xcode image button alpha


    【解决方案1】:

    您可以查看 GKTank 示例了解如何注册和使用触摸。

    您必须先注册才能获取触摸事件,然后在事件内部检查位置,并确定它是否会击中您的图形。为此,您必须知道圆形按钮的尺寸和形状,然后确定触摸是在它的内部还是外部。

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        if (myButtonIsActive) {
            CGPoint tPoint;
            UITouch *thumb = [[event allTouches] anyObject];
            tPoint = [thumb locationInView:thumb.view];
            // check here if tPoint is inside of the button shape/circle
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多