If you paste the button directly on the Tableviewcontroller, it will cause this to scroll, and here are two ways to implement the fixed position suspension button on the TableView:
1. Paste TableView on view, then paste the hover button on the top of view
2. Use window
First look at the final effect, add a hover button on the Tableviewcontroller, which cannot scroll as the view Scrolls
First, introduce the first method above:
1 Create the properties of the TableView and bottom buttons
Screen width
#define KSCREENW [UIScreen mainscreen].bounds.size.width
//Screen height
#define KSCREENH [UIScreen Mainscreen].bounds.size.height
@interface Broadcastliveviewcontroller () <uitableviewdatasource, Uitableviewdelegate>
@property (nonatomic) UITableView *liveslisttable;
@property (nonatomic) UIButton *bottombutton;
@end
2 Create the property to the top of the
@implementation Broadcastliveviewcontroller
-(void) viewdidload {
[super viewdidload];
CGRect clientrect = [UIScreen mainscreen].bounds;
_liveslisttable = [[UITableView alloc] Initwithframe:cgrectmake (0, 0, ClientRect.size.width, CLIENTRECT.SIZE.HEIGHT-65) Style:uitableviewstyleplain];
[Self.view addsubview:_liveslisttable];
_liveslisttable.delegate = self;
_liveslisttable.datasource = self;
Self.bottombutton = [UIButton buttonwithtype:uibuttontypecustom];
Self.bottomButton.frame = CGRectMake (kScreenW-80, kScreenH-140,);
[Self.bottombutton setbackgroundimage:[uiimage imagenamed:@ "recordlive"] forstate:uicontrolstatenormal];
[Self.bottombutton addtarget:self Action: @selector (ONTAPLIVEBTN) forcontrolevents:uicontroleventtouchupinside];
[Self.view AddSubview:self.bottomButton];
3 Implement button Events
-(void) ontaplivebtn
{
NSLog (@ "click bottom Button");
}
Next, we'll introduce the second method:
1 Create a Window,button property to prevent window from being freed
Screen width
#define KSCREENW [UIScreen mainscreen].bounds.size.width
//Screen height
#define KSCREENH [UIScreen Mainscreen].bounds.size.height
@interface Broadcastliveviewcontroller () <uitableviewdatasource, Uitableviewdelegate>
@property (strong,nonatomic) UIWindow *window;
@property (strong,nonatomic) UIButton *button;
@end
2 Create window and button
The system has only one window by default this time we need to set the Windowlevel
window does not need to be added to any view
-(void) createbutton{
_button = [UIButton buttonwithtype:uibuttontypecustom];
[_button setbackgroundimage:[uiimage imagenamed:@ "recordlive"] forstate:uicontrolstatenormal];
_button.frame = CGRectMake (0, 0,);
[_button addtarget:self Action: @selector (ONTAPLIVEBTN) forcontrolevents:uicontroleventtouchupinside];
_window = [[UIWindow alloc]initwithframe:cgrectmake (kScreenW-80, kScreenH-80,);];
_window.windowlevel = uiwindowlevelalert+1;
_window.backgroundcolor = [Uicolor redcolor];
_window.layer.cornerradius =;
_window.layer.maskstobounds = YES;
[_window Addsubview:_button];
[_window makekeyandvisible];//key statement, displaying window
}
3 Delay Loading window, note that we need to create this suspension button after the Rootwindow creation is complete.
-(void) viewdidload {
[super viewdidload];
[Self performselector: @selector (Createbutton) Withobject:nil afterdelay:1];
}
4 Implement button Events
-(void) ontaplivebtn
{
NSLog (@ "click bottom Button");
}
Note:: Finally add a small function to make the tableview up and down when the button animation effect appears and disappeared, here is pulled away, the next drag out of the present
-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{
if (Scrollview.contentoffset.y > Self.offsety & & Scrollview.contentoffset.y > 0) {//Up slide
//button disappears
[UIView TransitionWithView:self.bottomButton duration:0.1 options:uiviewanimationoptiontransitionnone animations:^{
self.bottomButton.frame = CGRectMake ( KSCREENW-80, kScreenH-65);
Completion:null];
} else if (Scrollview.contentoffset.y < self.offsety) {//Slide down
//button appears
[UIView transitionwithview: Self.bottombutton duration:0.1 options:uiviewanimationoptiontransitionnone animations:^{
Self.bottomButton.frame = CGRectMake (kScreenW-80, kScreenH-140);
Completion:null];
}
self.offsety = scrollview.contentoffset.y;//Changes current offset to cache offset
}
The above is a small set to introduce the Android development in the TableView to add a suspension button on the method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!