Ios disable tap status bar to scroll top năm 2024
A lesser known user-interface feature on the iPhone is that touches in the status bar will usually scroll the main Show This will work in your application when exactly one
2 from
4 method on a
6
6 is extremely rare so I'll explain how to make it work. Once you create the subclass of
drawerController = [[HiddenDrawerViewController alloc] init];
// Position the drawer below the status bar
CGRect drawerFrame = drawerController.view.frame;
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
drawerFrame.origin.x = statusBarFrame.origin.x;
drawerFrame.size.width = statusBarFrame.size.width;
drawerFrame.origin.y = statusBarFrame.origin.y + statusBarFrame.size.height;
// For the animation, move the drawer up by its own height.
drawerFrame.origin.y -= drawerFrame.size.height;
// Place the drawer and add it to the window
drawerController.view.frame = drawerFrame;
[window addSubview:drawerController.view];
// Start the animation
[UIView beginAnimations:nil context:nil];
// Move the table down
CGRect tableFrame = viewController.view.frame;
tableFrame.origin.y += drawerFrame.size.height;
viewController.view.frame = tableFrame;
// Move the drawer down
drawerFrame.origin.y += drawerFrame.size.height;
drawerController.view.frame = drawerFrame;
// Commit the animation
[UIView commitAnimations];
drawerController = [[HiddenDrawerViewController alloc] init];
// Position the drawer below the status bar
CGRect drawerFrame = drawerController.view.frame;
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
drawerFrame.origin.x = statusBarFrame.origin.x;
drawerFrame.size.width = statusBarFrame.size.width;
drawerFrame.origin.y = statusBarFrame.origin.y + statusBarFrame.size.height;
// For the animation, move the drawer up by its own height.
drawerFrame.origin.y -= drawerFrame.size.height;
// Place the drawer and add it to the window
drawerController.view.frame = drawerFrame;
[window addSubview:drawerController.view];
// Start the animation
[UIView beginAnimations:nil context:nil];
// Move the table down
CGRect tableFrame = viewController.view.frame;
tableFrame.origin.y += drawerFrame.size.height;
viewController.view.frame = tableFrame;
// Move the drawer down
drawerFrame.origin.y += drawerFrame.size.height;
drawerController.view.frame = drawerFrame;
// Commit the animation
[UIView commitAnimations];
int retVal = UIApplicationMain(argc, argv, @"CustomApplication", nil);
drawerController = [[HiddenDrawerViewController alloc] init];
// Position the drawer below the status bar
CGRect drawerFrame = drawerController.view.frame;
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
drawerFrame.origin.x = statusBarFrame.origin.x;
drawerFrame.size.width = statusBarFrame.size.width;
drawerFrame.origin.y = statusBarFrame.origin.y + statusBarFrame.size.height;
// For the animation, move the drawer up by its own height.
drawerFrame.origin.y -= drawerFrame.size.height;
// Place the drawer and add it to the window
drawerController.view.frame = drawerFrame;
[window addSubview:drawerController.view];
// Start the animation
[UIView beginAnimations:nil context:nil];
// Move the table down
CGRect tableFrame = viewController.view.frame;
tableFrame.origin.y += drawerFrame.size.height;
viewController.view.frame = tableFrame;
// Move the drawer down
drawerFrame.origin.y += drawerFrame.size.height;
drawerController.view.frame = drawerFrame;
// Commit the animation
[UIView commitAnimations];
7. The difficult part is then working out from the
4 which events are status bar touch events — unfortunately, the
5 method returns an empty array for status bar touches. Instead, we delve into the secret
6. I previously accessed
6 in my post Synthesizing a touch event on the iPhone. In that post, I created a
8 class and a fake
9 class to access the required fields. This time, I'm going to use a different approach and jump straight to the data I need.
drawerController = [[HiddenDrawerViewController alloc] init];
// Position the drawer below the status bar
CGRect drawerFrame = drawerController.view.frame;
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
drawerFrame.origin.x = statusBarFrame.origin.x;
drawerFrame.size.width = statusBarFrame.size.width;
drawerFrame.origin.y = statusBarFrame.origin.y + statusBarFrame.size.height;
// For the animation, move the drawer up by its own height.
drawerFrame.origin.y -= drawerFrame.size.height;
// Place the drawer and add it to the window
drawerController.view.frame = drawerFrame;
[window addSubview:drawerController.view];
// Start the animation
[UIView beginAnimations:nil context:nil];
// Move the table down
CGRect tableFrame = viewController.view.frame;
tableFrame.origin.y += drawerFrame.size.height;
viewController.view.frame = tableFrame;
// Move the drawer down
drawerFrame.origin.y += drawerFrame.size.height;
drawerController.view.frame = drawerFrame;
// Commit the animation
[UIView commitAnimations];
5 by the normal route. If you want to re-enable this behavior, you can take the `UIScrollView`7 line out of the `UIScrollView`8 block and put it in the main method body. Animating the drawerThe
1. All that's required is to animate the drawer's view in and push the table's view down:
If you download the whole project, you'll see that there's also an animate up and remove branch that gets run if the `UIScrollView`2 already exists. ConclusionYou can download the HiddenDrawer sample project (30kB) to see the whole application in action. A hidden drawer under the status bar isn't necessarily something that every iPhone application should have but the obscure, secretive nature of it appeals to me. The approach of determining which
4 we want by the `UIScrollView`4 field in the
6 is a little precarious. Apple are free to change the structure of
6 at any time, which could cause your application to misbehave or crash so this type of code would need to be tested on each iPhone OS release to ensure that it still works. How do I stop my iPhone from scrolling to the top?To solve iPhone scrolls on its own, try adjusting the 3D or haptic touch sensitivity as follows:. Launch the Settings app from your device.. Next, scroll down to choose Accessibility.. Under the Physical and Motor, hit Touch option.. Choose 3D & Haptic Touch.. Here, toggle on the 3D Touch.. How do I turn off scroll top?Set overflow-x to Hidden to Disable Horizontal Scroll Bar in CSS. For disabling the horizontal scrolling we can set the property overflow-x to hidden along with the height is set to 100%. Everything else remains the same. Let's see the implementation for this. How do I turn off scroll feature?overflow. property. Here are two possible ways to achieve this: ... . overflow. property to.. hidden. . This will hide any content that overflows the body and prevent scrolling. ... . position. property to.. fixed. and the.. width. and.. height. properties to.. 100% . This will fix the body element in place, effectively disabling scrolling.. |