From Portrait mode to Landscape mode in iOS5, iOS6 - ios6

I want to turn only one of my views within my app to landscape right.
All my other views are in portrait mode. Previous view is in portrait mode. I pushed landscape view to portrait view. How can I do it correctly?
in my landscape view controller:
//Orientation
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
// New Autorotation support
-(BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeRight;
}

You can use this in you view controller
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
this will make sure the orientation is landscape right.

For changing the orientation in a device you can do sum thng like this..
-(void)viewDidLoad
{
orientation = [[UIDevice currentDevice] orientation];
if(intOrientation == UIInterfaceOrientationLandscapeRight)
orientation = UIDeviceOrientationLandscapeRight;
}
Hope it helps you

I've solved. Thanks Sang. I used this example:
Also see this
Or this

Related

How do you stop scrolling to top when grid store is reloaded - take 2

I have an app that uses ExtJS 3.3.0. It uses an EditorGridPanel in which after the store is reloaded - I would like it to preserve the scroll position of the grid rather than sending it back up to the top.
Since it's an earlier version of ExtJS - this does not work.
viewConfig: {
preserveScrollOnRefresh: true
}
I thought I had found a solution per Zeke's suggestion to use a scrollTo function like so:
//Save position
var top = grid.getView().scrollergetScroll().top;
//Restore position
grid.getView().scroller.scrollTo('top',top);
This works great - except that after it's done reloading it goes right back up to the top. Basically this would be a perfect solution if only I didn't need preserve the cursor position after reloading the store.
grid().getStore().reload({
callback: function (response) {
//Works at this point
grid.getView().scroller.scrollTo('top',top);
}
}
//However the cursor pops right back up to the top after popping out of
//reload() block
Thanks in advance
This is a little kludgy - maybe the best strategy is just not to use older versions of ExtJS - but this seems to work okay.
Basically just declare some global variables that can be seen from anywhere in the file - one is a flag to indicate that the event that triggers the reload has occured (rowClicked), and one to represent the last known position of the scrollbar
var rowClicked = false;
var prevScrollPosition = -1;
When the event occurs that will trigger the re-load - set the global variable rowClicked to true
rowclick: function(grid, rowIndex, event) {
rowClicked = true;
Then in the listeners of the grid use the rowClicked variable to determine when to re-position the scrollbar.
listeners : {
bodyscroll: function(sl, st) {
if (rowClicked) {
getScenarioLineOrderNumbersGrid().getView().scroller.scrollTo('top',prevScrollPosition);
rowClicked = false;
}
prevScrollPosition = st;
}
Kludgy - but it works.

Calling setTitleTextAttributes on UIBarButtonItem does not have any impact on iOS 11

I am using an appearance proxy in didFinishLaunchingWithOptions to set UIBarButtonItem title font across the project like this:
UIBarButtonItem.appearance().setTitleTextAttributes([
NSAttributedStringKey.font: customFont
]
, for: .normal)
What I would like to do is to change this font based on user choice?
So upon the user choosing a font I store it in UserDefaults and I send a local notification to those view controllers I know have UIBarButtonItems and I reset each directly like this:
navigationItem.leftBarButtonItems?.forEach { $0.setTitleTextAttributes([NSAttributedStringKey.font: ...], for: .normal) }
navigationItem.rightBarButtonItems?.forEach { $0.setTitleTextAttributes([NSAttributedStringKey.font: ...], for: .normal) }
navigationItem.backBarButtonItem?.setTitleTextAttributes([NSAttributedStringKey.font: customFont], for: .normal)
This works as expected in iOS 10 but in iOS 11 it doesn't have an immediate impact on either left, right or back bar button items.
The back bar button item gets adjusted to the new font if a view controller is popped and then pushed again to the navigation stack - the bar button items don't change until the next app run.
I am naturally doing the same thing with navigation bar title so in the AppDelegate:
UINavigationBar.appearance().titleTextAttributes = [
NSAttributedStringKey.font: ...
]
if #available(iOS 11.0, *) {
UINavigationBar.appearance().largeTitleTextAttributes = [
NSAttributedStringKey.font : ...
]
}
And in each view controller I reset these values again and titles instantly change font.
I tried to set bar button items title text attributes to the new font in each control state, namely: [.normal, .highlighted, .disabled] with no luck.
I also tried to set navigationItem.leftBarButtonItem to a new instance of UIBarButonItem hoping this will have the new font but the button disappears completely :D
Last thing I tried was to call setNeedsDisplay and layoutIfNeeded on the navigation bar but still nothing happens.
A sample project of the case could be found here
Here's a super hacky mechanism to work around what appears to be an obvious bug (or undocumented optimization):
for controlState in [UIControlState.disabled, .highlighted, .normal] {
self.changeBarButtonFont(barButtonItem: self.updateButton, font: font, controlState: controlState)
self.changeBarButtonFont(barButtonItem: self.selectButton, font: font, controlState: controlState)
}
private func changeBarButtonFont(barButtonItem: UIBarButtonItem, font: UIFont, controlState: UIControlState) {
barButtonItem.title = barButtonItem.title! + " "
barButtonItem.setTitleTextAttributes([NSAttributedStringKey.font : font], for: controlState)
DispatchQueue.main.async
{
barButtonItem.title = barButtonItem.title?.trimmingCharacters(in: CharacterSet.whitespaces)
}
}
Note that this does not work 100% as rapid taps on the 'Change font' won't register. But perhaps you could work this out?

How to `presentViewController` with custom animation on iOS 6?

How can I have custom animation for view controller presented with presentViewController method on iOS 6+ ? I want the new VC's view to zoom in from some point.
I'm using the following routine to fade in new controller:
CATransition* transition = [CATransition animation];
transition.duration = 1;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromBottom;
[self.view.window.layer addAnimation:transition forKey:kCATransition];
[self presentViewController:viewController animated:NO completion:nil];
But I'm not sure how and whether it's possible to zoom in view this way.

How can I present a ModalViewController from a UIActivity item picked from UIActivity View Controller?

I am working on an app that presents some data in a detailViewController. I have a rightBarButton in the navbar that presents a UIActivityViewController that is filled with my own UIActivity sublclassed items. Most of them work fine as they are just changing a small aspect to the data from the detail view, but I need one of them to open a modalViewController when selected. I keep getting the following warning from the console.....
Warning: Attempt to present <UINavigationController: 0x1fd00590>
on <UITabBarController: 0x1fde1070> which is already presenting <MPActivityViewController: 0x1fd2f970>
I suppose it is worth noting that the app doesn't crash but the modal view doesn't appear either. I am assuming that the UIActivityViewController is a modal view itself and you can only display one of those at a time so the task is to figure out how to perform my segue after the ActivityView has disappeared, but thats where I am stumped. I welcome any help, thoughts or feedback. I've tried google but haven't had much luck, I assume because The UIActivityViewController is so new.
Here is my setup so far,
my UIActivity objects have a delegate set to the detailViewController for a custom protocol that lets the detailViewController perform the data changes and then update its view.
for the activities in question that should present the modalView controller I have tried a few approaches that all get the same warning.
None of These Works!!!
1) simply tried performing segue from my delegate method
- (void) activityDidRequestTransactionEdit
{
NSLog(#"activityDidRequestTransactionEdit");
[self performSegueWithIdentifier:#"editTransaction" sender:self];
}
2)tried setting a completion block on the UIActivityViewController and having my delegate method set a bool flag that the modal view should be shown(self.editor)
[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
NSLog(#"completed dialog - activity: %# - finished flag: %d", activityType, completed);
if (completed && self.editor) {
[self performSegueWithIdentifier:#"editTransaction" sender:self];
}
}];
3) subclassing the UIActivityViewController itself, giving it the detailView as a delegate, and overriding it's dismissViewControllerAnimated: method with my own completion block
- (void) dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
[super dismissViewControllerAnimated:flag completion:^{
[self.MPActivityDelegate activityDidRequestTransactionEdit];
}];
}
The working Solution
In the UIActivity subclass you need to override this method like so
- (UIViewController *) activityViewController {
MPEditMyDataViewController *controller = [[MPEditMyDataViewController alloc] init];
controller.activity = self; // more on this property below
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
return navController;
}
in your MPEditMyDataViewController.h (the view controller the chosen action should produce)
You need a property back to the activity subclass like so
#property (strong, nonatomic) MPEditMyDataActivity *activity;
in your MPEditMyDataViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:#selector(cancel)];
self.navigationItem.leftBarButtonItem = cancelButton;
}
// here's how you dismiss the view controller when you are done with it
// after saving the changes to your data or whatever the view controller is supposed to do.
-(void) cancel
{
NSLog(#"Cancel Button Pushed");
[self.activity activityDidFinish:YES];
}
#end
Did some more documentation digging and found this method for UIActivity subclassing
- (UIViewController *) activityViewController
it gets my view controller to pop up like I wanted by returning it from here instead of trying to segue it from my detailViewController. Now to figure out how to dismiss it when I'm done with it!!!!

How to go to first page after(before) sorting in extJs grid

I have extJs 4.1 grid with paging. For this grid applied remoteSort(maybe remoting style of sorting doesn't matter) behaviour. After sort click(click on header) I wanna go to first page. How can I achive this? Maybe exists presort callback in what I can cancel loading data and forward loading to first page with store.loadPage(1)?
P.S. Sorry for english.
This code is part of the FiltersFeature.js file.
Take a look at how when to specify (local: false) it goes to first page automagically ;)
reload : function () {
var me = this,
store = me.view.getStore();
if (me.local) {
store.clearFilter(true);
store.filterBy(me.getRecordFilter());
store.sort();
} else {
me.deferredUpdate.cancel();
if (store.buffered) {
store.pageMap.clear();
}
store.loadPage(1);
}
}
What you have to do is configure the feature with local: false.

Resources