2013-08-23 6 views
7

मैं एनीमेशन के साथ दबाए बटन के बाद UIView दिखाना चाहता हूं, मैं दृश्य दिखा सकता हूं लेकिन मैं इसे फिर से छिपाने में असमर्थ हूं। बटन को दबाए रखने के लिए मेरा कोड है राय।आईफोन में एनीमेशन के साथ UIView को छुपाएं/दिखाएं

sliderView.frame = CGRectMake(130, 20, 0, 0); 
    [UIView animateWithDuration:0.25 animations:^{ 
    sliderView.frame = CGRectMake(130, 30, 100, 200); 
    }]; 

UIView छिपाने के लिए:: UIView दिखाएँ करने के लिए

 [UIView animateWithDuration:0.25 animations:^{ 
    sliderView.frame = CGRectMake(130, 30, 0, 0); 
    }]; 

कोड दृश्य के ऊपर का उपयोग एनीमेशन के साथ दिखाया जा रहा है लेकिन छुपा नहीं। किसी को भी यह कैसे छिपाने के लिए पता है, कृपया मदद, धन्यवाद

+0

कोड आप के लिए नीचे 'sliderView' हटना चाहिए तैनात की कोशिश कुछ भी तो नहीं। वास्तव में क्या होता है? आप हमें नहीं बताते कि वास्तविक समस्या क्या है। – rmaddy

+0

मैंने अपना प्रश्न संपादित किया है। – user2586519

+0

वह कोड कैसे दिखा सकता है? यह फ्रेम की चौड़ाई और ऊंचाई को 0 तक घटा देता है। क्या आप सुनिश्चित हैं कि दृश्य को छिपाने के लिए कोड कहा जा रहा है? – rmaddy

उत्तर

18

आपका कोड काम करता है, मैं इसे इस्तेमाल किया है।

#import <UIKit/UIKit.h> 

@interface StackoverflowTestViewController : UIViewController 
@property (strong, nonatomic) IBOutlet UIView *cautionView; 


- (IBAction)btnToggleClick:(id)sender; 
@property (strong, nonatomic) IBOutlet UIButton *btnToggle; 
@end 


मीटर फ़ाइल:
ज फ़ाइल नीचे कोड देखो

#import "StackoverflowTestViewController.h" 

@interface StackoverflowTestViewController() 

@end 

@implementation StackoverflowTestViewController 

bool isShown = false; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (IBAction)btnToggleClick:(id)sender { 
    if (!isShown) { 
     _cautionView.frame = CGRectMake(130, 20, 0, 0); 
     [UIView animateWithDuration:0.25 animations:^{ 
      _cautionView.frame = CGRectMake(130, 30, 100, 200); 
     }]; 
     isShown = true; 
    } else { 
     [UIView animateWithDuration:0.25 animations:^{ 
      _cautionView.frame = CGRectMake(130, 30, 0, 0); 
     }]; 
     isShown = false; 
    } 
} 
@end 
+0

धन्यवाद बिन्ह ली, मैं भी उस UIView पर छविदृश्य जोड़ना चाहता हूं, तो क्या मैं छविदृश्य के फ्रेम को UIView जैसे बदल सकता हूं ?? – user2586519

+0

कोई समस्या नहीं आदमी, (1)।आप उस UIView में ImageView जोड़ सकते हैं और उस UIView (2) पर फ्रेम बदल सकते हैं बिना किसी समस्या के छविव्यू के ऊपर UIView बदलें – MOBYTELAB

+0

@BinhLee मैं आपके कोड के लिए उपयोग कर रहा हूं कि _cautionView एनिमेटेड है। मैंने उस _cautionView में दो UILabel जोड़ दिया था। एनिमेट करते समय वह लेबल छुपा नहीं है। – Thangavel

0

लागू प्रारंभिक/शुरू करने फ्रेम आप के दृश्य ऐसे

myButton.tag = 101;

और की तरह अपने बटन के

sliderView.frame = CGRectMake(130, 480, 100, 200); 

को टैग है आपकी बटन विधि

-(void)MyButonMethod:(UIButton *)sender 
{ 
    if(sender.tag == 101) 
    { 
    [UIView animateWithDuration:0.25 animations:^{ 
     sliderView.frame = CGRectMake(130, 30, 100, 200); 
    }]; 

    sender.tag = 102; 
    } 
    else 
    { 
    [UIView animateWithDuration:0.25 animations:^{ 
     sliderView.frame = CGRectMake(130, 480, 100, 200); 
    }];  
    sender.tag = 101; 
    } 
} 
+0

http://stackoverflow.com/a/29080894/1442541 – evya

0

इसे आज़माएं:

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:.25]; 
[sliderView setFrame:CGRectMake(130, 30, 0, 0)]; 
[UIView commitAnimations]; 
+2

ये पुराने और पुराने हैं। ऐप्पल अनुशंसा करता है कि आप ब्लॉक संस्करणों का उपयोग करें (जैसा कि मूल प्रश्न में दिखाया गया है)। – rmaddy

4

आप अपने स्लाइडर व्यू को छुपाने के लिए अल्फा संपत्ति और UIView की छिपी हुई संपत्ति का उपयोग कर सकते हैं। निम्नलिखित कोड का प्रयास करें:

/*To unhide*/ 
[sliderView setHidden:NO]; 
sliderView.frame = CGRectMake(130, 20, 0, 0); 
[UIView animateWithDuration:0.25 animations:^{ 
    sliderView.frame = CGRectMake(130, 30, 100, 200); 
    sliderView.alpha = 1.0f; 
} completion:^(BOOL finished) { 
}]; 

/*To hide*/ 
[UIView animateWithDuration:0.25 animations:^{ 
    sliderView.frame = CGRectMake(130, 30, 0, 0); 
    [sliderView setAlpha:0.0f]; 
} completion:^(BOOL finished) { 
    [sliderView setHidden:YES]; 
}]; 
+0

यह मेरे लिए काम करता .. आप कहानी बोर्ड का उपयोग कर रहे हैं, तो आप एक UIView जोड़ने और यह आकार के रूप में आप चाहते हैं कर सकते हैं। यदि ऐसा है तो आप स्लाइडरव्यू.फ्रेम के CGRectMake मानों को हटा सकते हैं –

6
-(void)fadeInAnimation:(UIView *)aView { 

    CATransition *transition = [CATransition animation]; 
    transition.type =kCATransitionFade; 
    transition.duration = 0.5f; 
    transition.delegate = self; 
    [aView.layer addAnimation:transition forKey:nil]; 
    } 

Add Subview: 

    [self.view addsubView:mysubview]; 
    [self fadeInAnimation:self.view]; 

Remove SubView: 

     [mySubView removefromSuperView]; 
     [self fadeInAnimation:self.view]; 
2

इस

- (IBAction)eventparameter:(id)sender 
{ 
    if ([self.parameterview isHidden]) 
    { 
     [UIView beginAnimations:@"LeftFlip" context:nil]; 
     [UIView setAnimationDuration:0.8]; 
     _parameterview.hidden=NO; 
     [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
     [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:_parameterview cache:YES]; 
     [UIView commitAnimations]; 
    } 
    else 
    { 
     [UIView transitionWithView:_parameterview 
          duration:0.4 
          options:UIViewAnimationOptionTransitionCurlUp 
         animations:NULL 
         completion:NULL]; 

     [self.parameterview setHidden:YES]; 
    } 
} 
संबंधित मुद्दे