Fast reach top with UIWindow
For example, add a uiwindow with no color in the status bar (add a button inside), which allows you to quickly return to the top of the current interface when clicking this button.
Core code
First, the use of UIWindow to reach the top
1. Create a new window
1) UIWindow level, the higher the level, the more it appears on the upper level (high window cover on the lower level window)
Uiwindowlevelnormal < Uiwindowlevelstatusbar < Uiwindowlevelalert
@interfaceappdelegate () @property (nonatomic, strong) UIWindow*Topwindow;@end@implementationappdelegate-(UIWindow *) topwindow{if(_topwindow = =Nil) {_topwindow=[[UIWindow alloc] init]; _topwindow.windowlevel=Uiwindowlevelalert; _topwindow.frame= CGRectMake (0,0, Chgscreenw, -); _topwindow.backgroundcolor=[Uicolor Clearcolor]; //This is important, the default is hidden, want to display must be manually set to No_topwindow.hidden =NO; [_topwindow Addgesturerecognizer:[[uitapgesturerecognizer alloc] initwithtarget:self action: @selector ( Topwindowclick)]; } return_topwindow;}
2. Traverse each window
-(void) topwindowclick{ *windows = [uiapplication sharedapplication].windows; for inch windows) {
Traverse all child controls under the window [self Searchsubviews:window];} }
3. Traverse all child controls under the window
/** * Search all child controls inside the Superview*/- (void) Searchsubviews: (UIView *) superview{ for(Uiscrollview *scrollviewinchsuperview.subviews) {[Self searchsubviews:scrollview]; //determine if it is ScrollView if(! [ScrollView Iskindofclass:[uiscrollviewclass]])Continue; //determine if the ScrollView is on the window (intersect)//calculates the ScrollView rectangle on the window coordinate systemCGRect Scrollviewrect =[ScrollView convertRect:scrollView.bounds ToView:scrollView.window]; CGRect Windowrect=ScrollView.window.bounds; //determines whether the ScrollView border crosses the window border if(! Cgrectintersectsrect (Scrollviewrect, Windowrect))Continue; //can come here to explain scrollview on the window, modify the offset, roll to the topCgpoint offset =Scrollview.contentoffset; Offset.y= -ScrollView.contentInset.top; [ScrollView Setcontentoffset:offset Animated:yes]; }}
4. Active call lazy Loading when program is active
// when the program is activated, call Topwindow-(void) Applicationdidbecomeactive: (uiapplication *) application { [ Self Topwindow];}
iOS Development-project requirements-quickly back to the top of the current interface