我已经看过一些关于在Objective-C中实现这一点的帖子,但我无法通过Swift做同样的事情.
具体来说,我无法弄清楚如何实现addPeriodicTimeObserverForInterval如下.
var player : AVAudioPlayer! = nil
@IBAction func playAudio(sender: AnyObject) {
playButton.selected = !(playButton.selected)
if playButton.selected {
let fileURL = NSURL(string: toPass)
player = AVAudioPlayer(contentsOfURL: fileURL, error: nil)
player.numberOfLoops = -1 // play indefinitely
player.prepareToPlay()
player.delegate = self
player.play()
startTime.text = "\(player.currentTime)"
endTime.text = NSString(format: "%.1f", player.duration)
} else {
player.stop()
}
Run Code Online (Sandbox Code Playgroud)
任何援助将不胜感激.
我有一个 podspec 设置如下:
Pod::Spec.new do |spec|
spec.name = "TMGAdvertising"
spec.default_subspecs = ["Core"]
*** [extra stuff removed] ***
spec.subspec 'Core' do |tmgadvertising|
*** [extra stuff removed] ***
end
spec.subspec 'Inneractive' do |inneractive|
inneractive.dependency "TMGAdvertising/Core"
inneractive.private_header_files = "TMGAdvertising/AdNetworkSupport/Inneractive/SDK/*.h", "TMGAdvertising/AdNetworkSupport/Inneractive/Adapters/*.h"
inneractive.public_header_files = "TMGAdvertising/AdNetworkSupport/Inneractive/InneractiveWrapper.h"
inneractive.source_files = ["TMGAdvertising/AdNetworkSupport/Inneractive/Adapters/*.{h,m,swift}", "TMGAdvertising/AdNetworkSupport/Inneractive/SDK/*.{h,m,swift}", "TMGAdvertising/AdNetworkSupport/Inneractive/InneractiveWrapper.{h,m,swift}"]
inneractive.vendored_frameworks = "TMGAdvertising/AdNetworkSupport/Inneractive/SDK/*.framework"
inneractive.pod_target_xcconfig = { 'OTHER_LDFLAGS' => ['-ObjC'] }
end
end
Run Code Online (Sandbox Code Playgroud)
我在 Obj-C(位于 TMGAdvertising 中)中为 Inneractive 框架编写包装类没有问题。这是我的 Obj-C 包装器示例之一:
#import "InneractiveWrapper.h"
@import IASDKCore;
@implementation InneractiveWrapper
+ (void)initializeSDK:(NSString *)appId {
[[IASDKCore sharedInstance] initWithAppID:appId];
}
@end …Run Code Online (Sandbox Code Playgroud) 文档表明我们可以在 tvOS 中使用它UISearchBar(Apple 当然在其搜索视图中使用它),但我在对象库中找不到它。
还有其他人有同样的问题吗?我还没有看到任何关于它的帖子或评论。
不幸的是,我不得不在这个程序中使用多个窗口,我不认为CardLayout会起作用,因为我不能在不同的布局之间保持任何按钮不变.所以我试图编写一个按钮来隐藏当前的JPanel(thePanel)并显示一个新的(thePlacebo).
我试图在ActionListener中隐藏thePanel,如下所示:
frame.getContentPane().remove(thePanel);
Run Code Online (Sandbox Code Playgroud)
我认为这样可行,但只要按下按钮就会冻结我的程序.
这是上下文代码的一大块:
public class Reflexology1 extends JFrame{
JButton button1, button2;
JButton movingButton;
JTextArea textArea1;
int buttonAClicked, buttonDClicked;
private long _openTime = 0;
private long _closeTime = 0;
JPanel thePanel = new JPanel();
JPanel thePlacebo = new JPanel();
final JFrame frame = new JFrame("Reflexology");
public static void main(String[] args){
new Reflexology1();
}
public Reflexology1(){
frame.setSize(600, 475);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Reflexology 1.0");
frame.setResizable(false);
button1 = new JButton("Accept");
button2 = new JButton("Decline");
movingButton = new JButton("Click Me");
ListenForAcceptButton lForAButton = new …Run Code Online (Sandbox Code Playgroud) 让我先说我知道我在这个凌乱的代码中违反了一些基本的Java原则,但是我很想在周二之前完成一个社交科学实验的程序,我不懂Java,所以我'我现在基本上只是摸索它.
有了这个免责声明,我有一个单独的程序工作,其中一个圆圈在屏幕上移动,用户必须点击它.它在它自己独立的类文件中工作正常,但是当我将代码添加到我的主程序时,它不再有效.我甚至不明白为什么repaint()调用我的paint()函数 - 就我而言,它是神奇的,但我注意到repaint()在我的测试程序中调用paint(),但不是更复杂的实际程序,我认为这就是为什么圆圈不再在我的程序上绘画.
整个代码如下:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.Ellipse2D;
import java.io.FileReader;
import java.io.IOException;
import java.util.Calendar;
public class Reflexology1 extends JFrame{
private static final long serialVersionUID = -1295261024563143679L;
private Ellipse2D ball = new Ellipse2D.Double(0, 0, 25, 25);
private Timer moveBallTimer;
int _ballXpos, _ballYpos;
JButton button1, button2;
JButton movingButton;
JTextArea textArea1;
int buttonAClicked, buttonDClicked;
private long _openTime = 0;
private long _closeTime = 0;
JPanel thePanel = new JPanel();
JPanel thePlacebo = …Run Code Online (Sandbox Code Playgroud) 我正在使用一个按钮来填充UIPickerView隐藏的内容UIVisualEffectView.用户单击按钮,VisualEffectView模糊其他所有内容,并PickerView显示其联系人列表中的所有名称(我正在使用SwiftAddressBook执行此操作.)
这很好用,除非用户单击按钮,UI会锁定大约5-10秒.我找不到任何CPU或内存使用量很大的证据.如果我只是将已排序的数组打印到控制台,它几乎立即发生.所以关于显示窗口的事情导致了这个错误.
@IBAction func getBffContacts(sender: AnyObject) {
swiftAddressBook?.requestAccessWithCompletion({ (success, error) -> Void in
if success {
if let people = swiftAddressBook?.allPeople {
self.pickerDataSource = [String]()
for person in people {
if (person.firstName != nil && person.lastName != nil) {
//println("\(person.firstName!) \(person.lastName!)")
self.pickerDataSource.append(person.firstName!)
}
}
//println(self.pickerDataSource)
println("done")
self.sortedNames = self.pickerDataSource.sorted { $0.localizedCaseInsensitiveCompare($1) == NSComparisonResult.OrderedAscending }
self.pickerView.reloadAllComponents()
self.blurView.hidden = false
}
}
else {
//no success, access denied. Optionally evaluate error
} …Run Code Online (Sandbox Code Playgroud) 作为序言:我知道代码很粗糙 - 我上周刚刚学习了Java,所以我可以将这个东西放到跨平台进行实验,这样即使我的学生也可以参加OS X机器的研究.
所以我现在在大约10台Windows机器上测试它没有问题,但在OS X上,frame3显示没有任何面板(例如只是一个空白帧).我现在在OS X机器上编译,我看到以下控制台输出:
Exception in thread "main" java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string
at java.awt.CardLayout.addLayoutComponent(CardLayout.java:190)
at java.awt.Container.addImpl(Container.java:1072)
at java.awt.Container.add(Container.java:363)
at Reflexology1.<init>(Reflexology1.java:150)
at Reflexology1.main(Reflexology1.java:51)
Run Code Online (Sandbox Code Playgroud)
该代码发布在http://pastebin.com/t3vqa0s6
是否有人知道在OS X下可能导致此问题的原因是什么?
java ×3
swift ×3
swing ×3
ios ×2
jpanel ×2
avfoundation ×1
avplayer ×1
cocoapods ×1
graphics2d ×1
jframe ×1
objective-c ×1
repaint ×1
tvos ×1
uisearchbar ×1
xcode ×1