[iphonex] [ios] Fixed dim background interface.

This commit is contained in:
Ilya Grechuhin 2017-12-27 15:36:37 +03:00 committed by Roman Kuznetsov
parent e80aad9b32
commit 5183b36b2f
3 changed files with 35 additions and 44 deletions

View file

@ -1,10 +1,11 @@
@objc(MWMDimBackground)
final class DimBackground: SolidTouchView {
private let mainView: UIView
private var tapAction: (() -> Void)!
private var tapAction: () -> Void
@objc init(mainView: UIView) {
@objc init(mainView: UIView, tapAction: @escaping () -> Void) {
self.mainView = mainView
self.tapAction = tapAction
super.init(frame: mainView.superview!.bounds)
backgroundColor = UIColor.fadeBackground()
autoresizingMask = [.flexibleWidth, .flexibleHeight]
@ -15,9 +16,7 @@ final class DimBackground: SolidTouchView {
fatalError("init(coder:) has not been implemented")
}
@objc func setVisible(_ visible: Bool, tapAction: @escaping () -> Void) {
self.tapAction = tapAction
@objc func setVisible(_ visible: Bool, completion: (() -> Void)?) {
if visible {
let sv = mainView.superview!
frame = sv.bounds
@ -32,6 +31,7 @@ final class DimBackground: SolidTouchView {
if !visible {
self.removeFromSuperview()
}
completion?()
})
}

View file

@ -36,7 +36,9 @@ final class NavigationControlView: SolidTouchView, MWMTextToSpeechObserver, MWMT
}
private lazy var dimBackground: DimBackground = {
DimBackground(mainView: self)
DimBackground(mainView: self, tapAction: { [weak self] in
self?.diminish()
})
}()
@objc weak var ownerView: UIView!
@ -52,17 +54,9 @@ final class NavigationControlView: SolidTouchView, MWMTextToSpeechObserver, MWMT
if isVisible {
addView()
} else {
dimBackground.setVisible(false) {}
DispatchQueue.main.async {
self.superview?.setNeedsLayout()
UIView.animate(withDuration: kDefaultAnimationDuration,
animations: { self.superview?.layoutIfNeeded() },
completion: { _ in
if !self.isVisible {
self.removeFromSuperview()
}
})
}
dimBackground.setVisible(false, completion: {
self.removeFromSuperview()
})
}
hiddenConstraint.isActive = !isVisible
}
@ -77,14 +71,11 @@ final class NavigationControlView: SolidTouchView, MWMTextToSpeechObserver, MWMT
guard isVisible && superview != nil else { return }
guard isExtended != oldValue else { return }
superview?.setNeedsLayout()
dimBackground.setVisible(isExtended, completion: nil)
extendedView.isHidden = !isExtended
extendedConstraint.isActive = isExtended
UIView.animate(withDuration: kDefaultAnimationDuration) { self.superview?.layoutIfNeeded() }
dimBackground.setVisible(isExtended) { [weak self] in
self?.diminish()
}
superview?.animateConstraints(animations: {
extendedConstraint.isActive = isExtended
})
}
}
@ -187,11 +178,9 @@ final class NavigationControlView: SolidTouchView, MWMTextToSpeechObserver, MWMT
speedWithLegend.append(NSAttributedString(string: info.speedUnits, attributes: routingLegendAttributes))
speedWithLegendLabel.attributedText = speedWithLegend
progressView.setNeedsLayout()
routingProgress.constant = progressView.width * info.progress / 100
UIView.animate(withDuration: kDefaultAnimationDuration) { [progressView] in
progressView?.layoutIfNeeded()
}
progressView.animateConstraints(animations: {
routingProgress.constant = progressView.width * info.progress / 100
})
}
@IBAction

View file

@ -360,7 +360,22 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) {
- (MWMDimBackground *)dimBackground
{
if (!_dimBackground)
_dimBackground = [[MWMDimBackground alloc] initWithMainView:self.view];
{
__weak auto wSelf = self;
auto tapAction = ^{
// In case when there are 2 touch events (dimBackgroundTap &
// menuButtonTouchUpInside)
// if dimBackgroundTap is processed first then menuButtonTouchUpInside
// behaves as if menu is
// inactive this is wrong case, so we postpone dimBackgroundTap to make
// sure
// menuButtonTouchUpInside processed first
dispatch_async(dispatch_get_main_queue(), ^{
wSelf.state = MWMBottomMenuStateInactive;
});
};
_dimBackground = [[MWMDimBackground alloc] initWithMainView:self.view tapAction:tapAction];
}
return _dimBackground;
}
@ -374,20 +389,7 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) {
if (menuActive)
[self.controller.view bringSubviewToFront:view];
__weak auto wSelf = self;
[self.dimBackground setVisible:menuActive
tapAction:^{
// In case when there are 2 touch events (dimBackgroundTap &
// menuButtonTouchUpInside)
// if dimBackgroundTap is processed first then menuButtonTouchUpInside
// behaves as if menu is
// inactive this is wrong case, so we postpone dimBackgroundTap to make
// sure
// menuButtonTouchUpInside processed first
dispatch_async(dispatch_get_main_queue(), ^{
wSelf.state = MWMBottomMenuStateInactive;
});
}];
[self.dimBackground setVisible:menuActive completion:nil];
view.state = state;
[self updateBadgeVisible:[[MapsAppDelegate theApp] badgeNumber] != 0];
}