简体   繁体   中英

How to slide in UIView from bottom in Landscape Mode

I have added a UIView to another 'main' view on IB. My application is in landscape mode only. I want to make it so that by pressing a button, this other UIView slides in from the bottom. So, currently it's not in the picture at all, but when the button is pressed, then the view appears from the bottom and slides into place. Later I will have the same button work as a toggle to then slide the UIVIew back out. The UIView is not the size of the screen, otherwise I would have presented it modally.

This is the code I've tried:

.m

-(IBAction)onGearBag:(UIButton *)sender
{

    [sender setEnabled:NO];
    [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        if (gearBag.transform.ty == 0) {
            [gearBag setTransform:CGAffineTransformMakeTranslation(0, -400)];
        }else{
            [gearBag setTransform:CGAffineTransformMakeTranslation(0, -200)];
        }
    }completion:^(BOOL done){
        //some completion handler
        [sender setEnabled:YES];
    }];
}

.h

@interface MyEquipmentViewController : PFViewController
{
    IBOutlet UIView *gearBag;
}
@property (strong, nonatomic) TabsTopBar *topbar;
- (IBAction)onPopoverButton:(UIButton *)sender;
- (IBAction)actionHelp:(id)sender;
- (IBAction)onGearBag:(id)sender;
@end

.h

@interface MyEquipmentViewController : PFViewController
{
    IBOutlet UIView *popoverInitAlert;
    __unsafe_unretained IBOutlet UIImageView *imageView;
    IBOutlet UIView *gearBag;
}

@property (strong, nonatomic) TabsTopBar *topbar;
- (IBAction)onPopoverButton:(UIButton *)sender;
- (IBAction)actionHelp:(id)sender;
- (IBAction)onGearBag:(id)sender;
@end

Simple view animation:

- (IBAction)myIBAction:(UIButton *)sender
{
    [sender setEnabled:NO];
    [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        if (mySecondView.transform.ty == 0) {
            [mySecondView setTransform:CGAffineTransformMakeTranslation(0, -400)];
        }else{
            [mySecondView setTransform:CGAffineTransformMakeTranslation(0, 0)];
        }
    }completion:^(BOOL done){
        //some completion handler
        [sender setEnabled:YES];
    }];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM