<i id='T564j'><tr id='T564j'><dt id='T564j'><q id='T564j'><span id='T564j'><b id='T564j'><form id='T564j'><ins id='T564j'></ins><ul id='T564j'></ul><sub id='T564j'></sub></form><legend id='T564j'></legend><bdo id='T564j'><pre id='T564j'><center id='T564j'></center></pre></bdo></b><th id='T564j'></th></span></q></dt></tr></i><div id='T564j'><tfoot id='T564j'></tfoot><dl id='T564j'><fieldset id='T564j'></fieldset></dl></div>

    1. <tfoot id='T564j'></tfoot>
    2. <small id='T564j'></small><noframes id='T564j'>

        <bdo id='T564j'></bdo><ul id='T564j'></ul>

      <legend id='T564j'><style id='T564j'><dir id='T564j'><q id='T564j'></q></dir></style></legend>

    3. 从另一个类修改 UIButton 的 alpha 属性

      时间:2023-07-06
      <tfoot id='BKmqD'></tfoot>
        <tbody id='BKmqD'></tbody>
        <bdo id='BKmqD'></bdo><ul id='BKmqD'></ul>

        <legend id='BKmqD'><style id='BKmqD'><dir id='BKmqD'><q id='BKmqD'></q></dir></style></legend>

          <small id='BKmqD'></small><noframes id='BKmqD'>

          <i id='BKmqD'><tr id='BKmqD'><dt id='BKmqD'><q id='BKmqD'><span id='BKmqD'><b id='BKmqD'><form id='BKmqD'><ins id='BKmqD'></ins><ul id='BKmqD'></ul><sub id='BKmqD'></sub></form><legend id='BKmqD'></legend><bdo id='BKmqD'><pre id='BKmqD'><center id='BKmqD'></center></pre></bdo></b><th id='BKmqD'></th></span></q></dt></tr></i><div id='BKmqD'><tfoot id='BKmqD'></tfoot><dl id='BKmqD'><fieldset id='BKmqD'></fieldset></dl></div>

                本文介绍了从另一个类修改 UIButton 的 alpha 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试从另一个类更改 UIButtonalpha.在设置我的 UIButton 的 alpha 属性中调用的函数实际上是被调用的,因为我已经在其中放置了一个 NSLog 并且我可以看到它是如何工作的.如果您能给我任何建议,我将不胜感激.

                I'm trying to change the alpha of an UIButton from another class. The function that is called in set the alpha property of my UIButton is actually called because I've put a NSLog there and I can see how it works. I'd be thankful if you could give me any suggestion.

                这是我当前的代码.

                ViewController.h

                - (void) setAlphaToButton;
                
                @property (strong, nonatomic) IBOutlet UIButton *myButton;
                

                ViewController.m

                @synthesize myButton;
                
                - (void) setAlphaToButton {
                    myButton.alpha = 0.5;
                    NSLog(@"Alpha set");
                }
                

                ImageViewSubclass.m

                - (void) tapDetected:(UITapGestureRecognizer *)tapRecognizer {
                    ViewController *VC = [[ViewController alloc] init];
                    [VC setAlphaToButton];
                }
                

                当按下图像视图时,在我的控制台中我得到:Alpha set.而且按钮没有变化.

                And when the image view is pressed, in my console I get: Alpha set. And the button doesn't change.

                推荐答案

                在您的代码中,分配并初始化了一个 ViewController 的实例,并在其上调用了 setAlphaToButton 方法.然后释放视图控制器,因为您没有保留它的对象.这就是为什么您看不到任何效果的原因;您调用该方法的 ViewController 实例永远不会出现在屏幕上.

                In your code, an instance of ViewController is alloced and inited, and the method setAlphaToButton is called on it. Then the view controller is released because you have no object retaining it. That's why you don't see any effect; the ViewController instance you call the method on never appears on screen.

                不清楚您的代码应该如何工作;调用 tapDetected 时是否存在 ViewController 的实例?如果是这种情况,并且这是您要更改其 alpha 的按钮的 ViewController,那么您需要引用 ViewController 的 那个 实例并在其上调用 setAlphaToButton.

                It's not clear how your code is supposed to work; do you have an instance of ViewController in existence when tapDetected is called? If this is the case, and this is the ViewController whose button you want to alter the alpha of, then you need to have a reference to that instance of ViewController and call setAlphaToButton on it.

                这篇关于从另一个类修改 UIButton 的 alpha 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:UISplitViewController 内的 UITabBarController 内的 UINavigationC 下一篇:UIButtons 在动画期间没有响应 - iOS Swift 3

                相关文章

                    <bdo id='nKDHn'></bdo><ul id='nKDHn'></ul>
                  <tfoot id='nKDHn'></tfoot>

                  <small id='nKDHn'></small><noframes id='nKDHn'>

                    <i id='nKDHn'><tr id='nKDHn'><dt id='nKDHn'><q id='nKDHn'><span id='nKDHn'><b id='nKDHn'><form id='nKDHn'><ins id='nKDHn'></ins><ul id='nKDHn'></ul><sub id='nKDHn'></sub></form><legend id='nKDHn'></legend><bdo id='nKDHn'><pre id='nKDHn'><center id='nKDHn'></center></pre></bdo></b><th id='nKDHn'></th></span></q></dt></tr></i><div id='nKDHn'><tfoot id='nKDHn'></tfoot><dl id='nKDHn'><fieldset id='nKDHn'></fieldset></dl></div>

                    <legend id='nKDHn'><style id='nKDHn'><dir id='nKDHn'><q id='nKDHn'></q></dir></style></legend>