Вы можете просто использовать видимость css: скрытый / видимый вместо отображения: none / block
div {
visibility:hidden;
-webkit-transition: opacity 1s ease-out;
-moz-transition: opacity 1s ease-out;
-o-transition: opacity 1s ease-out;
transition: opacity 1s ease-out;
opacity: 0;
}
parent:hover > div {
opacity: 1;
visibility: visible;
}
Да, вы можете. Я только что протестировал, и он работает. Вам просто нужно добавить свой таймер в основной цикл запуска NSRunLoopCommonModes:
RunLoop.main.add(yourTimerName, forMode: .commonModes)
import NotificationCenter
class TodayViewController: UIViewController, NCWidgetProviding {
@IBOutlet weak var strTimer: UILabel!
var timer = Timer()
func updateInfo() {
strTimer.text = Date().description
}
override func viewDidLoad() {
super.viewDidLoad()
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateInfo), userInfo: nil, repeats: true)
RunLoop.main.add(timer, forMode: .commonModes)
}
func widgetPerformUpdate(completionHandler: @escaping (NCUpdateResult) -> Void) {
completionHandler(.newData)
}
}
Я знаю, что это вопрос Swift, но я нашел, что он ищет код Objective-C, поэтому другие могут тоже.
-(void) viewDidLoad
{
[NSTimer scheduledTimerWithTimeInterval:1 // update more than once a second to appear in sync with the system clock
target:self
selector:@selector(updateTimes:)
userInfo:nil
repeats:YES];
}
-(void) updateTimes:(NSTimer *)timer
{
// Update Widget UI as required
}