我正在尝试用最少的 UI 制作一个 iOS Action 应用程序扩展。基本上它只会显示一个进度指示器,直到操作完成。我只是希望能够为 View 设置动画,使其从顶部向下滑动,然后在 Action 完成后向上滑动。如果有人熟悉 Instapaper 的 Share 扩展,那么这就是我正在寻找的那种基本 UI。
问题是当我尝试复制此功能时 - 我只有一个小的 UIView
从顶部向下动画 - 我的视野后面有黑色背景。我不知道如何使背景透明,以便我的 View 后面的东西仍然可见。有谁知道如何做到这一点?
作为一个起点,我只是使用由 Xcode 创建的默认 Action 扩展模板......
ActionViewController.m
文件添加 viewWillAppear
动画 View 的方法(使用 1 秒动画,以便容易看到黑色背景):代码:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGRect currFrame = self.view.frame;
CGRect newFrame = currFrame;
newFrame.origin.y -= newFrame.size.height;
self.view.frame = newFrame;
[UIView animateWithDuration:1.0 animations:^{
self.view.frame = currFrame;
}];
}
当它运行时, View 动画从顶部向下滑动。但是,您看到的不是调用应用程序的 UI,而是黑色背景。
我尝试了很多方法 - 更改
modalPresentationStyle
(似乎没有做任何事情),将整个 View 设置为隐藏(这只会使整个屏幕变黑)等。作为引用,这是使用 iOS 9.3.2 和 Xcode 7.3.1。
最佳答案
据我了解Apple docs
In iOS, an Action extension:
- Helps users view the current document in a different way
- Always appears in an action sheet or full-screen modal view
- Receives selected content only if explicitly provided by the host app
Action 扩展总是出现在 iPhone 上的全屏 View 中这一事实可能意味着没有办法拥有透明背景。
我确信共享扩展可以动画(我自己做过)你想要它并具有透明背景。这就是为什么 Instapaper 的 分享 扩展工作得很好。
关于具有透明背景的 iOS Action 应用程序扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38708701/