【问题标题】:Showing a subview temporary临时显示子视图
【发布时间】:2011-04-11 19:41:01
【问题描述】:

我想要实现的是在几秒钟内显示一个视图而无需用户干预。与iphone上按下音量控制时出现的铃声音量视图效果相同:

我有一个带有图像的滚动视图,在图像中点击,声音开始播放,再次点击它会暂停。我想实现上述效果只是为了通知动作(显示播放/暂停图像)。

我希望我已经完美地解释了这个问题。

非常感谢您的帮助。

问候 哈维

【问题讨论】:

  • 你自己试过了吗?你会发现这里的很多人不会帮助你,除非你自己先尝试过。
  • 您可以将 alpha 属性设置为 1/0 来使 UIView 可见/不可见
  • 第一次发布您的代码,我们可以提供帮助

标签: iphone objective-c cocoa-touch ios uiview


【解决方案1】:

假设你有一些继承自UIViewController 的类。您可以使用以下代码:

const int myViewTag = 10001;
const int myInterval = 1; // define the time you want your view to be visible

- (void)someAction {
    //this could be your `IBAction` implementation
    [self showMyView];
    [NSTimer scheduledTimerWithTimeInterval:myInterval
                                     target:self
                                   selector:@selector(hideMyView)
                                   userInfo:nil
                                    repeats:NO];
}


- (void) showMyView {
    //you can also use here a view that was declared as instance var
    UIView *myView = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 120, 120)] autorelease];

    myView.tag = myViewTag;
    [self.view addSubview:myView];
}

- (void) hideMyView {
    //this is a selector that called automatically after time interval finished
    [[self.view viewWithTag:myViewTag] removeFromSuperview];
}

你也可以在这里添加一些动画,但这是另一个问题:)

【讨论】:

  • @Black Frog,别担心,我刚刚拒绝了它
  • 谢谢@NR4TR,这就是我想要实现的目标
猜你喜欢
  • 1970-01-01
  • 2014-04-08
  • 2015-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-03
相关资源
最近更新 更多