iPhone 上滑视图控制器用于音频播放器控制?

发布于 2024-10-02 05:28:30 字数 2983 浏览 0 评论 0原文

我有一个简短的音频剪辑,当按下按钮时会播放。我想从底部创建一个向上滑动的控制器,其中包含一个暂停/播放按钮和一个显示音频长度的滑块。我还希望控制器后面的视图在控制器可见时保持可滚动。我相信这排除了使用 UIAlertView 或 UIActionSheetView 因为两者都会导致下面的视图保持静态。实现这一点的最佳方法是什么?

编辑:我在这里找到了一个有用的教程:http://iosdevelopertips.com/user-interface/sliding-views-on-and-off-screen-creating-a-reusable-sliding-message-widget.html

我能够修改它以获得我想要的东西。但是,如果我想使用 nib 文件制作动画,我将在哪里/如何调用它?

#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 Cleanup

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

@end

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 Cleanup

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

@end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜灵血窟げ 2024-10-09 05:28:30

“滑动控制器”是什么意思?只是从底部向上滑动的视图吗?如果是这样,您只需创建一个包含按钮的 UIView 并为其设置动画即可。对于动画,您可以使用 UIView beginAnimations:context:commitAnimations

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文