如何在横向模式下从底部滑入UIView

时间:2012-09-22 15:21:15

标签: iphone ios xcode animation uiview

我在IB的另一个“主要”视图中添加了一个UIView。我的应用程序仅处于横向模式。我想这样做,按下按钮,这个另一个UIView从底部滑入。因此,目前它根本不在图片中,但是当按下按钮时,视图将从底部显示并滑动到位。稍后我将使用相同的按钮作为切换,然后将UIVIew滑回。 UIView不是屏幕的大小,否则我会以模态方式呈现它。

这是我尝试过的代码:

的.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

1 个答案:

答案 0 :(得分:1)

简单视图动画:

- (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];
    }];
}