Ich möchte UIView anzeigen, nachdem die Schaltfläche mit der Animation gedrückt wurde. Ich kann die Ansicht anzeigen, aber ich kann sie nicht erneut ausblenden. Drücken Sie diese Taste. Hier ist mein Code, um die Ansicht anzuzeigen/auszublenden.
sliderView.frame = CGRectMake(130, 20, 0, 0);
[UIView animateWithDuration:0.25 animations:^{
sliderView.frame = CGRectMake(130, 30, 100, 200);
}];
So blenden Sie die UIView aus:
[UIView animateWithDuration:0.25 animations:^{
sliderView.frame = CGRectMake(130, 30, 0, 0);
}];
Die obige Codeansicht wird mit Animation angezeigt, aber nicht ausgeblendet ..__ Weiß jemand, wie er sie versteckt, helfen Sie bitte, danke
Ihr Code funktioniert, ich habe ihn benutzt. Code unten sehen
. h Datei:
#import <UIKit/UIKit.h>
@interface StackoverflowTestViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIView *cautionView;
- (IBAction)btnToggleClick:(id)sender;
@property (strong, nonatomic) IBOutlet UIButton *btnToggle;
@end
. m Datei:
#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
-(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];
Sie können die Alpha-Eigenschaft und die verborgene Eigenschaft von UIView verwenden, um Ihren SliderView auszublenden. Versuchen Sie den folgenden Code:
/*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];
}];
versuche dies
- (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];
}
}
Übernehmen Anfangs-/Startbild Ihrer Ansicht ist
sliderView.frame = CGRectMake(130, 480, 100, 200);
Geben Sie ein Tag wie beispielsweise ein
myButton.tag = 101;
Und deine Knopfmethode
-(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;
}
}
Versuche dies:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.25];
[sliderView setFrame:CGRectMake(130, 30, 0, 0)];
[UIView commitAnimations];