UIAccessibility on subview of UIWINDOW - uiaccessibility

Hi have added Viewcontroller view into UIWINDOWS as below
[[[UIApplication sharedApplication] keyWindow] addSubview:self.myviewcontroller.view];
But now for myviewcontroller view UIAccessibility is not working. Its getting whatever backside of that window.

I figured solution,
we should add subview on topmost window.
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:self.myviewController.view];

Related

How to restore keyWindow (NSView - Appkit)

I have some code which opens a modal window (itself composed from a few views) and makes it closed when we click anywhere on it.
here is some part of code:
int myFunc()
{
// Create views
NSPanel *panel = ...;
CustomNSTextView * textView = ... ;
CustomNSImageView * imageView = ...;
[view addSubview:textView];
[view addSubview:imageView];
[panel setContentView:view];
[[NSApplication sharedApplication] runModalForWindow:panel];
NSView* parentView = [view superview];
[[parentView window] makeFirstResponder:parentView];
[textView release];
[imageView release];
[view release];
[panel release];
}
#implementation CustomNSTextView : NSTextView
- (void) mouseDown:(NSEvent *)theEvent
{
#pragma unused(theEvent)
[[NSApplication sharedApplication] stopModal];
}
#implementation CustomNSImageView : NSImageView
- (void) mouseDown:(NSEvent *)theEvent
{
#pragma unused(theEvent)
[[NSApplication sharedApplication] stopModal];
}
The bug is after the window is closed, the application (that launched the modal window), won't receive any key event anymore (while it still was as the modal window was still open).
Only after I refocus on the application, it will receive key events again.
Please anyone gives me some idea, I could not find something relevant on the net.
Thanks
Nathaniel

iOS 7 resizing main view to adjust for status bar

Rather than having to adjust every single XIB in my application, I was hoping to just resize the main view.
I did this in AppDelegate, with partial success:
if (kCFCoreFoundationVersionNumber > kCFCoreFoundationVersionNumber_iOS_6_1) {
NSLog(#"iOs 7 detected");
frame.origin.y += 20.0;
frame.size.height -= 20.0;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
}
self.window = [[[UIWindow alloc] initWithFrame:frame] autorelease];
The whole window moves down, the status bar shows nicely, BUT all my views are now 20 pixels too tall for the screen, as if my -20 for the height did not have any effect.
Does anyone have any idea as to how I can get the main window to be the right height?
Thanks!
A possible solution could be the following: Instead of change the window size you could try to change the root view controller frame size. This solutions works for me . As a reference here is my code. I have added this inside my root view controller and I call it in my custom init method:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
self.edgesForExtendedLayout = UIRectEdgeNone;
CGRect frame=self.view.frame;
frame.origin.y=20;
frame.size.height-=20;
self.view.frame=frame;
}
I got it to work by overriding the root viewcontroller and attach my "main" viewcontroller to that. Maybe there is a better way to work and do this, this is one way.
In your AppDelegate (applicationDidFinishLaunch method)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Override rootviewcontroller with an empty viewcontroller
window.rootViewController = [[UIViewController alloc] init];
//Setup my custom viewcontroller
MyViewController *vc = [[MyViewController alloc] init];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[window.rootViewController addChildViewController:vc];
[window.rootViewController.view addSubview:vc.view];
// Put in the desired size and position.
vc.view.frame = CGRectMake(10.0, 100.0, 300.0, 100.0);
...
Just for fun. If you are doing your project with StoryBoard, same process but fetching the StoryBoard identifier. Note that in this case you must set the StoryBoard ID in Interface Builder for your main viewcontroller.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
// Fetch viewcontroller from the storyboard ID that you have set in Interface Builder
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"MyMainViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[window.rootViewController addChildViewController:vc];
[window.rootViewController.view addSubview:vc.view];
// Put in the disired size and position.
vc.view.frame = CGRectMake(10.0, 100.0, 300.0, 100.0);
...

How to change speed of segue between ViewControllers

Is it possible to control segue speed?
I have checked the documentation but there is no given method by Apple.
But I am more looking for ideas to hack in and change lower level code to make segueing in slow motion.
Below code is of custom segue, and you can set duration of transition in code.
- (void)perform
{
UIViewController *src = (UIViewController *) self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;
[UIView transitionFromView:src.view
toView:dst.view
duration:3.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:NULL];
}
Sample project is here in GitHub:https://github.com/weed/p120805_CustomSegue
You can download and just run it. I wish this is help for you.
to prevent zombies creation i think better to do use subview add/remove as well:
- (void)perform
{
UIView *src = ((UIViewController *) self.sourceViewController).view;
UIView *dst = ((UIViewController *) self.destinationViewController).view;
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
[window insertSubview:dst aboveSubview:src];
[UIView transitionFromView:src
toView:dst
duration:1.5
options:UIViewAnimationOptionTransitionCrossDissolve
completion:^(BOOL finished){
[src removeFromSuperview];
window.rootViewController = self.destinationViewController;
}];
}
this is if you are not using navigation controller!

ViewController Delegate

is it possible to access a ViewController's methods from the appDelegate, like it is possible inverse with the following code:?
AppDelegate *ad = (AppDelegate *) [[UIApplication sharedApplication] delegate];
When I try
ViewController *vc = (ViewController *) [[UIApplication sharedApplication] delegate];
I get an error...
Thanks!
In your AppDelegate, assuming viewController is your rootViewController, you can get a list of all view controllers on the stack by with:
NSLog(#"List of current active view controllers:%#", self.viewController.navController.viewControllers);
To access a specific view controller in the viewControllers:
[[self.viewController.navController.viewControllers objectAtIndex:i] someMethodOfThatViewController];
ViewController *vc = (ViewController *)[UIApplication sharedApplication].keyWindow.rootViewController;
or if your delegate have properties
YourAppDelegate *ad = (YourAppDelegate*)[UIApplication sharedApplication].delegate;
ViewController *vc = ad.yourViewControllerProperty;

Loading an OverlayView from XIB -vs- programmatically for use with UIImagePickerController

I am currently making a camera app for iPhone and I have a strange phenomenon that I can't figure out. I would appreciate some help understanding.
When recreating an overlay view for passing to UIImagePickerController, I have been successfully been able to create the view programmatically. What I haven't been able to do is create the view with/without controller in IB, load it and pass it to the overlay pointer successfully. If I do it via IB, the view is not opaque and obscures the view of the camera completely. I can not figure out why.
I was thinking that the normal view pointer might be assigned when loading from XIB and therefore overwrite the camera's view, but I have an example programmatically where view and overlayView are set equal in the controller class. Perhaps the load order is overwriting a pointer?
Help would be appreciated... kind regards.
This works fine...
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// dislodge the MainView from the MainViewController
//
MainViewController *aController = [[MainViewController alloc] init]; //WithNibName:#"MainView" bundle:nil];
aController.sourceType= UIImagePickerControllerSourceTypeCamera;
aController.delegate= aController;
aController.showsCameraControls= NO;
// Programmatically load the MainView from the Nib and assign it as the OverlayView instead
//
NSArray* nibViews= [[NSBundle mainBundle] loadNibNamed:#"MainView" owner:aController options:nil];
UIView* uiView= [nibViews objectAtIndex:0];
uiView.opaque= NO;
uiView.backgroundColor= [UIColor clearColor];
aController.cameraOverlayView= uiView;
self.mainViewController = aController;
[aController release];
mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window addSubview:[mainViewController view]];
[window makeKeyAndVisible];
}
This DOESN'T...
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// dislodge the MainView from the MainViewController
//
MainViewController *aController = [[MainViewController alloc] initWithNibName:#"MainView" bundle:nil];
aController.sourceType= UIImagePickerControllerSourceTypeCamera;
aController.delegate= aController;
aController.showsCameraControls= NO;
aController.cameraOverlayView= aController.view;
self.mainViewController = aController;
[aController release];
mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window addSubview:[mainViewController view]];
[window makeKeyAndVisible];
}