开发者

iPhone slide-up view controller for audio player controls?

开发者 https://www.devze.com 2023-01-24 20:20 出处:网络
I have a short audio clip that plays when a button is pressed. I want to create a slide-up controller from the bottom that contains a pause/play button and a slider bar displaying the length of the au

I have a short audio clip that plays when a button is pressed. I want to create a slide-up controller from the bottom that contains a pause/play button and a slider bar displaying the length of the audio. I also want the view behind the controller to remain scrollable while the controller is visible. I believe this excludes using a UIAlertView or UIActionSheetView as both cause the view below to remain static. What is the best way to implement this?

EDIT: i found a helpful tutorial here: http://iosdevelopertips.com/user-interface/sliding-views-on-and-off-screen-creating-a-reusable-sliding-message-widget.html

and I was able to modify this to get something of what I want. However, if I would like to animate using a nib file where/how would i call this?

#import "SlidingMessageController.h"


@interface SlidingMessageController(private)
- (void)hideMsg;
@end

@implementation SlidingMessageController
#pragma mark -
#pragma mark Private Methods


- (void)hideMsg;
{
    // Slide the view off screen
    CGRect frame = self.frame;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.75];

    frame.origin.y = 480;
    frame.origin.x = 0;
    self.frame = frame;

    //to autorelease the Msg, define stop selector
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

    [UIView commitAnimations];
}

- (void)animationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context 
{
    [self removeFromSuperview];
    [self release];
}

#pragma mark -
#pragma mark Initialization

- (id)initWithDirection:(int)dir;
//- (id)initWithTitle:(NSString *)title message:(NSString *)msg
{
  if (self = [super init]) 
  {
      //Switch direction based on slideDirection konstant
      switch (dir) {
          case kSlideUp:    //slideup
              // Notice the view y coordinate is offscreen (480)
              // This hides the view

              // What should I be doing here if I want to get the nib file???       
              self.frame = CGRectMake(0,480,320, 90);
              [self setBackgroundColor:[UIColor blackColor]];
              [self setAlpha:.87];


              newY = 380;
              newX = 0;
              myDir = 0;
              break;
              default:
              break;
      }


  }

  return self;
}

#pragma mark -
#pragma mark Message Handling

- (void)showMsgWithDelay:(int)delay
{
//  UIView *view = self.view;
    CGRect frame = self.frame;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.75];

    // Slide up based on y axis
    // A better solution over a hard-coded value would be to
    // determine the size of the title and msg labels and 
    // set this value accordingly

    frame.origin.y = newY;
    frame.origin.x = newX;
    self.frame = frame;

    [UIView commitAnimations];

    // Hide the view after the requested delay
    [self performSelector:@selector(hideMsg) withObject:nil afterDelay:delay];

}

#pragma mark -
#pragma mark C开发者_C百科leanup

- (void)dealloc 
{
  if ([self superview])
    [self removeFromSuperview];
  [super dealloc];
}

@end


What do you mean with a "slide-up controller"? Just a view that slides up from the bottom? If so, you can just create a UIView with the buttons in it, and animate it. For the animation you can use UIView beginAnimations:context: and commitAnimations.

0

精彩评论

暂无评论...
验证码 换一张
取 消