मैं एक प्रभाव बनाने की कोशिश कर रहा हूं जहां UIBarButtonItem में एक कस्टम छवि दूसरी छवि में बदल जाती है। अब तक, मैं निम्नलिखित कोड के साथ पहली छवि को भंग करने में सक्षम हूं। क्या कोई सुझाव दे सकता है कि मैं एक ही समय में दूसरी छवि को कैसे फीका कर सकता हूं?

//Create barbuttonitem in viewwillappear
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
    [b setFrame:CGRectMake(12, 0, 22, 22)];
    [b addTarget:self action:@selector(menuButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [b setImage:[UIImage imageNamed:@"firstimage.png"] forState:UIControlStateNormal];
    UIBarButtonItem * myBarButton = [[UIBarButtonItem alloc] initWithCustomView:b];

//Animate in viewDidAppaer

 [UIView animateWithDuration:1.0
                          delay:1.0
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{
                         self.myBarButton.customView.alpha = 0;
                     }
                     completion:^(BOOL finished) {
UIImage *secondImage = [UIImage imageNamed:@"menu2.png"];
    [self.myBarButton setImage:secondImage];//THis does not change image
                                 self.myBarButton.customView.alpha = 1;//no animation
                             }];
0
user6631314 22 मई 2018, 13:44

2 जवाब

सबसे बढ़िया उत्तर

आप कुछ इस तरह इस्तेमाल कर सकते हैं

[UIView transitionWithView:self.myBarButton
                      duration:0.3
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{ [self.myBarButton setImage:secondImage];}
                    completion:nil];
1
Prasad Parab 22 मई 2018, 14:57
Try this code    

    @interface ViewController ()
        {
            UIBarButtonItem * myBarButton;
            NSTimer *time;
            UIButton *b;
        }
        @end

        @implementation ViewController

        - (void)viewDidLoad {
            [super viewDidLoad];
            b = [UIButton buttonWithType:UIButtonTypeCustom];
            [b setFrame:CGRectMake(12, 0, 22, 22)];
            [b addTarget:self action:@selector(menuButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
            [b setImage:[UIImage imageNamed:@"AddPlus_Yellow.png"] forState:UIControlStateNormal];
            myBarButton = [[UIBarButtonItem alloc] initWithCustomView:b];
            self.navigationItem.rightBarButtonItem=myBarButton;
            time = [NSTimer scheduledTimerWithTimeInterval: 2.0 target: self selector:@selector(onTick:) userInfo: nil repeats:NO];
            // Do any additional setup after loading the view, typically from a nib.
        }

        -(void)onTick:(NSTimer *)timer {

            [b setImage:[UIImage imageNamed:@"filter.png"] forState:UIControlStateNormal];
[time invalidate];

        }
0
Jigar Darji 22 मई 2018, 15:47