UIWebview scrollsToTop not working when a UIScrollview is present as subview - objective-c

I'm having an issue with setScrollsToTop: on UIWebView. the webview is a subview of the root view controller and on viewDidLoad I set:
[self.webView.scrollView setScrollsToTop:YES];
However when I then tap the status bar the webview won't scroll to the top. On another modal tableViewController inside the app it works fine, without even setting setScrollsToTop:YES. This is the code in applicationDidFinishLaunching inside the app delegate:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.f = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
self.window.rootViewController = self.f;
[self.window makeKeyAndVisible];
return YES;
How can I make it work?
EDIT: It seems like a UIScrollview that is in the same view is causing the problem. How can I make it work with the UIScrollView?

Try setting setScrollsToTop:NO on the UIScrollView.
According to the docs on setScrollsToTop: in UIScrollView,
This gesture works on a single visible scroll view; if there are
multiple scroll views (for example, a date picker) with this property
set, or if the delegate returns NO in scrollViewShouldScrollToTop:,
UIScrollView ignores the request.

use the answer here: UIScrollView + UIWebView = NO scrollsToTop
worked for me like a charm.
i had a UIScrollView with a UIWebView embedded.

Maybe those code will solve you problem if I get the problem.
self.automaticallyAdjustsScrollViewInsets = NO;
CGSize containerSize = self.view.frame.size;
self.webView.frame = CGRectMake(0, 64, containerSize.wdith, containerSize.height - 65);
Sometime the self.automaticallyAdjestsScrollViewInsets is not wokring as usual. So, just turn off it.

Related

Displaying a Custom UIView on Springboard (Jailbreak)

I created a custom UIView programmatically. Does anyone know what class and what method I would use to display this on the springboard? I want my UIView to display on the springboard, and when a user opens an app I want it to show up there too. I have been searching through the private headers for some time and I can't seem to find what I'm looking for. I am developing a jailbreak tweak with iosopendev. Also could you tell me if the class is a viewcontroller or just a view?
If you want the UIView to show anywhere (on SpringBoard and in apps), you should create a new UIWindow above the others and show your view in it like this :
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.windowLevel = UIWindowLevelAlert + 2;
[window setHidden:NO];
[window setAlpha:1.0];
[window setBackgroundColor:[UIColor clearColor]];
[window addSubview:yourView];
You can hook some methods of SpringBoard such as :
- (void)applicationDidFinishLaunching:(id)arg1
And then, your code should be like this :
- (void)applicationDidFinishLaunching:(id)arg1
{
%orig;
NSLog(#"----- applicationDidFinishLaunching -----");
UIWindow *_uiwindow = [[UIWindow alloc] initWithFrame:CGRectMake(100,100,120,100)];
_uiwindow.windowLevel = UIWindowLevelStatusBar;
_uiwindow.hidden = NO;
[_uiwindow setBackgroundColor:[UIColor redColor]];
}
To add more custom views,just add subview to _uiwindow. Hope that will help you.

How to setup view in UIViewController

I've created an almost-empty UIViewController class named MyViewController. In the viewDidLoad I'm setting the title and adding a close-button to the navigationItem.leftBarButtonItem.
I'm presenting my MyViewController like this:
MyViewController *myViewController = [[MyViewController alloc] init];
UINavigationController *nc = [[UINavigationController alloc] myViewController];
nc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:nc animated:YES];
When the viewController is presented, the background of it's view is just black. How can I setup it's view to fill-out the screen with an empty view -- just like when the UIViewController is setup in a Storyboard?
I've tried adding the following to the viewDidLoad, but the view is still black:
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
By default a VC's view gets created in -loadView which you usually neither call, nor override. It gets called automatically the first time you request the the VC's view property.
The view's size is automatically set to the 'empty space', like everything except for the status bar without a NavigationController, minus the navbar when using one etc. You shouldn't worry about its size - usually it's just fine.
You can add your own views in -viewDidLoad and remove them again (for low-memory reasons) in -viewDidUnload.
You can add an UIImageView with custom image and then sent it to back
So in your viewcontrollers viewDidLoad
UIImageView *back = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"MyBG"]];
[self.view addSubview:back];
[self.view sendSubViewToBack:back];
If you are using a XIB file you should init the view controller through the method initWithNibName: bundle:

UINavigationController — left and right flip animation between pushes and pops when presented via presentViewController

Supposed you've got:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *rootViewController = [[UIViewController alloc] init];
rootViewController.view.backgroundColor = [UIColor whiteColor];
[self.window setRootViewController:rootViewController];
[self.window makeKeyAndVisible];
UINavigationController *modal = [[UINavigationController alloc] initWithRootViewController:[[PTFrontViewController alloc] init]];
modal.modalPresentationStyle = UIModalPresentationFormSheet;
[rootViewController presentViewController:modal animated:YES completion:NULL];
return YES;
}
whereas PTFrontViewController and PTBackViewController view controllers have nothing interesting for sake of this example.
How could you push an instance of PTBackViewController from PTFrontViewController animating as in UIViewAnimationTransitionFlipFromLeft or UIViewAnimationTransitionFlipFromRight?
I am already well aware of these three things:
this is not exactly how you should make use of presentViewController
there is a good reason for UINavigationController's default animation
there are several answers how to "customize" UINavigationController's default animation while pushing and poping, but if you try the code for your self you will notice that when a view controller is presented via presentViewController there are drop shadows and background views that won't get animated correctly
So please answer taking these things in mind. Thank you.
First - forget UINavigationController. If you don't need the default animation, just put a UINavigationBar into your controllers. It will get a little easier.
Second - this is a difficult problem, you can't create such an animation only within the modal controller because the background wouldn't be repainted.
Sincerely, the easist solution I see is too forget the modal controller and just add the view controller as a child of your root controller. Then you can control all the animations but you have to write everything by yourself (including the background fading).

UIImageView subclass not passing touches to controller subviews

When I add a UIImageView subclass (fullscreen) behind a couple of UIButton subclass instances, those buttons stop receiving the touches and don't function anymore. Nothing I have tried has worked to restore their connectivity to user touches.
I have tried:
a) Using a UIImageView subclass for the front view (that receives the touches) and making sure setUserInteractionEnabled is YES. Result: UIButtons are not responding when the UIView is present.
b) Explicitly passing the touches from the front view to the view controller in hopes that it will do the right thing. Result: UIButtons are not responding to the touches.
c) Calling the touchesBegan, touchesMoved and touchesEnded methods directly on the button I want to interact with when any touch on the front UIView is received. Result: Strikingly, the buttons don't respond even when I am cramming the touch events down their throat.
d) Passing the touches from the front view to the UIViewController, and iterating over all subviews handing out the touches manually. I included a touchesBegan method showing how I tried to do this. When executed the loop is infinite, it never progresses past the first view (is of type FrameUIView).
I know this problem is likely the result of my lack of understanding of proper view hierarchy or the responder chain.
if I comment the last view created after the button, then the buttons work fine. Is there something special about UIButtons in this respect?
Here is the code.
I have a UIViewController subclass, in it:
- (void)loadView {
mainAppView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.view = mainAppView;
frameImageView = [[FrameUIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
frameImageView.image = [UIImage imageNamed:[[[ThemeController sharedInstance] currentTheme] frameImageFilename]];
[frameImageView setUserInteractionEnabled:YES];
[mainAppView addSubview:frameImageView];
zoomInButton = [[CustomUIButton alloc] initWithFrame:CGRectMake(controlsOriginX + zoomWidth + lightWidth, controlsOriginY, zoomWidth, controlsHeight)];
[zoomInButton setTitle:#"+" forState:UIControlStateNormal];
[[zoomInButton titleLabel] setFont:[UIFont systemFontOfSize:28]];
[zoomInButton addTarget:self action:#selector(doMyAction) forControlEvents:UIControlEventTouchDown];
[zoomInButton addTarget:self action:#selector(cancelMyAction) forControlEvents:UIControlEventTouchUpInside];
[mainAppView addSubview:zoomInButton];
FrameFrontUIView *frameFrontImageView = [[FrameFrontUIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
frameFrontImageView.image = [UIImage imageNamed:[[[ThemeController sharedInstance] currentTheme] frameFrontImageFilename]];
[frameFrontImageView setUserInteractionEnabled:YES];
[mainAppView addSubview:frameFrontImageView];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView *view in self.view.subviews) {
NSLog(#"view is a %#", [view description]);
[view touchesBegan:touches withEvent:event];
}
}
Anyone with a tip on how to do this wins the internets and a cookie. Also accepting revolvers for russian roulette mayhem. Thank you.
Have you tried using the buttons without the image view behind them? Subclassing UIButton is not advisable. The way to instantiate UIButtons is with factory methods:
UIButton* myButton = [UIButton buttonWithType:UIButtonTypeCustom];
So my guess is that the CustomUIButton instances you have created are not properly set up.
This question is old, but I just ran into the same problem.
The solution I used is to create a container UIView, then add the UIImageView as a subview, then add the buttons, text boxes, etc. over that. Seems to work well.
I don't really understand why this is an issue with using a UIImageView as the superview for buttons.

UIView transition and animation

I understand modal views cover the entire screen. But I really want a view that covers only half the screen just like the keyboard. So, please tell me why this doesn't work
MyController *controller = [[MyController alloc] initWithNibName:#"MyView" bundle:nil];
CGRect frame = CGRectMake(0,44,768,264);
[controller view].frame = frame;
contoller.delegate = self;
[[self view] addSubView:[controller view]];
[controller release];
I am trying to add a sub view to my current view and make it appear where the keyboard appears.
It throws a BAD ACCESS exception
In my code (above), I was using a custom UIViewController with it's own view [set to UIView on IB]. I couldn't get it to work by setting frame for the view controller's view.
So I added a custom UIView without a Nib file with all the controls (buttons, textfields) added on initWithFrame.
MyCustomView = [[MyCustomView] alloc] initWithFrame:frame delegate:self];
[self.view addSubView:MyCustomView];
Thanks for your comment, Jacob.