I want to cancel animation of back preview. How can I do that?
.controller('DemoController', function($scope, $ionicHistory) {
$scope.goBack() = function(){
$ionicHistory.viewHistory().backView.go();
}
})
Use $ionicHistory.nextViewOptions() for this purpose.
This method can be useful to override certain view/transition defaults right before a view transition happens.
Available options:
disableAnimate: Do not animate the next transition.
disableBack: The next view should forget its back view, and set it to null.
historyRoot: The next view should become the root view in its history stack.
Set property disableAnimate to true for disable the animation
Controller
$ionicHistory.nextViewOptions({
disableAnimate: true
});
Refer
Related
I have this View Controller that contains the bigTitle label (Please ignore the right-to-left):
In this situation, (bigTitle is visible), I want the top Navigation Bar to not contain any text (but still be visible!)
But when the user scrolls down in the scrollView and the bigTitle is not visible anymore, I want the Navigation Bar to contain the text that was in the bigTitle, in this case it's Welcome to our app!
This is my current code (right now it's not completed and it's in the viewDidLoad()) (feel free to change anything you want):
_ = Timer.scheduledTimer(withTimeInterval: 0.05, repeats: true, block: { (time) in
// If bigTitle is visible on the screen
if true {
self.bigTitle.alpha = 1
self.navBar.title = "" // navBar is my Navigation Bar reference
} else {
self.bigTitle.alpha = 0
self.navBar.title = self.bigTitle.text
}
})
Thanks!
Don't use a timer to track what happens when scrolling; use the scroll view's delegate. As the user scrolls, you are notified in the delegate method. Examine the label's frame; convert it to window coordinates to discover whether it is off the screen.
I am using AVPlayerController and I have added a subview on top of AVPlayerController. As Soon the subview is displayed I want to shift focus from the player to the Subview and focus the UIButton added on top of that Subivew. I have tried preferredfocusview but its a read-only property and I cannot change it. Can anyone pelase assist. Thanks a lot.
First of all, preferredFocusView is deprecated so you should use preferredFocusEnvironments instead.
It is a computed property, which means you don't assign to it, you override it:
override var preferredFocusEnvironments: [UIFocusEnvironment] {
//if subview exists, return the subview or the button, whichever is focusable
return [subview]
//otherwise use the default implementation of AVPlayerController
return super.preferredFocusEnvironments
}
You should also call self.setNeedsFocusUpdate() and self.updateFocusIfNeeded() to request a focus update when you add the subview.
I am trying to use a custom segue, that makes the view 'scroll' to the right or left, when a button is clicked. I added a custom class that looks like this
class horizontalSegue : UIStoryboardSegue {
override func perform() {
var oldView = self.sourceViewController.view as UIView
var newView = self.destinationViewController.view as UIView
oldView.window?.insertSubview(newView, aboveSubview: oldView)
newView.center.x = oldView.center.x + oldView.frame.width
newView.center.y = oldView.center.y
UIView.animateWithDuration(0.6, animations: { newView.center = oldView.center }, completion: { finished in Void })
}
}
but the problem is that after I segue once, I cannot segue back to the view I segued from. I think its because of the way I have the oldView and newView declared, the app isn't updating which view is which, so its segueing back to the current view when I try to segue to the first view.
If I am correct, how would I make sure the app updates which view is which?
Apple documentation says: "Regardless of how you perform the animation, at the end of it, you are responsible for installing the destination view controller (and its views) in the right place so that it can handle events. For example, if you were to implement a custom modal transition, you might perform your animations using snapshot images and then at the end call the presentModalViewController:animated: method (with animations disabled) to set up the appropriate modal relationship between the source and destination view controllers."
May be you should add something like
[self.navigationController pushViewController:vc animated:NO]
into your animation's completion handler?
I have a swipe gesture in my app that when you swipe, it changes the text on screen. How would I make it so it looks like it is sliding to the new text rather than just instantly changing the text?
You could do one thing!!!add a view behind your gesture view ,that view should look same as that of gesture View(should even have same text),and once after recognizing gesture bring that view in-front of your gesture view it should have old text(don't update the text) and update your gesture view's text ones it moves behind newly added view, just change the frame of newly added view so that it gives a sliding kind of effect(change its width) once after the completing animation bring that view back to gesture view and change its frame to previous its previous value.
check this sample:
func handleGesture(sender:UISwipeGestureRecognizer) {
//bring background view to front
self.view.bringSubviewToFront(self.backGroundView)
self.gestureView.userInteractionEnabled = false
//capture its initialAutolayout constraint
let backgroundViewSpaceConstarint = self.backGroundViewLeftSpaceConstraint.constant
UIView.animateWithDuration(2, animations: { [unowned self]() -> Void in
self.someRandomValue++
// update text label in gesture view which is behind background View
self.gestureViewTextLabel.text = "swiped \(self.someRandomValue) times"
//slide backgroundView in required direction by using autolayout
self.backGroundViewLeftSpaceConstraint.constant = self.backGroundView.bounds.size.width
self.backGroundView.layoutIfNeeded()
}) { [unowned self](completion:Bool) -> Void in
//after animation complition bring gesture view to the front.
self.backgroundTextLabel.text = "swiped \(self.someRandomValue) times"
self.gestureView.userInteractionEnabled = true
//upadte background view so that it will look the same for next swipe
self.backGroundViewLeftSpaceConstraint.constant = backgroundViewSpaceConstarint
//send the background view behind gesture view
self.view.sendSubviewToBack(self.backGroundView)
}
}
In my app I have a "home" screen from which I can present a hamburger menu (coded as a modal transition in Storyboard).
The menu is a UITableView where a user will select a row. The menu has a delegate method which calls the following function in the presenting screen (my "home" screen)
// Menu delegate method
func menuDidExit(menuVC:MenuVC) {
self.dismissViewControllerAnimated(true, completion: {
// After dismissal of menu, call the chosen option
if let selectedOption = menuVC.menuSelection {
self.performSegueWithIdentifier(menuVC.menuSelection?.rawValue, sender: self)
}
})
}
This function will both dismiss the menu view controller, and then (once that transition is complete), present a second view controller based upon the chosen menu option, using the "performSegueWithIdentifier" command.
The issue that I have is that while the menu dismiss works fine (the menu slides off screen gracefully) - there is no animation for the presentation of the next view controller - it simply appears on screen after the menu has been dismissed.
I can call the desired view controller via a button/segue, and all works well, however when it is part of the completion block above it fails to animate the transition. This leads me to believe that there is something fundamentally wrong with my approach - hence the question, what is the correct way to push a second view controller after handling the dismissal of the first.
Many thanks for any suggestions
I think you can use this:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
self.dismiss(animated: true) {
//dismiss your menu here
}
}
Hope it can help you.
Please let me know if it not work.
Thanks