le mie informazioni di contatto
Posta[email protected]
2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
A volte incontriamo uno scenario così interattivo: abbiamo un UITableView
Posizionalo in una finestra pop-up. Questa finestra pop-up può essere visualizzata e scomparsa scorrendo (scorrendo con la mano). Quindi questo UITableView viene inserito nella finestra pop-up e può essere fatto scorrere per visualizzare alcuni contenuti, ad esempio informazioni sul prodotto e commenti (simile alla finestra pop-up dei commenti di Douyin) e quando si scorre verso il basso, se tableView è scivolato verso l'alto, è possibile rispondere al gesto di scorrimento e continuare a far scorrere la finestra pop-up verso il basso.
Innanzitutto, abbiamo un tableView nella visualizzazione popup. Questo tableView può scorrere normalmente. Quindi, aggiungiamo un gesto di scorrimento alla visualizzazione popup, modifichiamo il frame del popup finestra.Pertanto, questa visualizzazione popup è un proxy che risponde ai gesti
quadrato e dentro
Aggiungiamo un gesto di scorrimento alla finestra pop-up e il metodo di risposta è handlePan:
Attraverso i test lo abbiamo scopertoQuando la nostra mano scorre su tableView, ogni volta che eseguiamo
Prima del metodo proxy scrollViewDidScroll di tableView, verrà eseguito il metodo handlePan.
Inoltre, durante uno scorrimento (viene conteggiato lo stesso scorrimento se la mano non esce dallo schermo),
Se è stato impostato nel metodo di risposta handlePan
self.tableView.panGestureRecognizer.enabled = NO causerà
self.tableView non scorrerà durante questa diapositiva, anche se self.tableView.panGestureRecognizer.enabled = YES è impostato dopo self.tableView.panGestureRecognizer.enabled = NO, non scorrerà.
Ciò dimostra che **In risposta a un gesto di scorrimento, self.tableView.panGestureRecognizer.enabled = NO ha la massima priorità
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"哈哈哈哈哈这里是执行scrollViewDidScroll self.panNum是%ld", self.panNum);
}
- (void)handlePan:(UIPanGestureRecognizer *)pan
{
self.tableView.panGestureRecognizer.enabled = YES;
NSLog(@"哈哈哈哈哈这是第%ld次响应滑动手势handlePan 方法", self.panNum);
if (self.panNum % 2 == 0) {
self.tableView.panGestureRecognizer.enabled = NO;
} else {
self.tableView.panGestureRecognizer.enabled = YES;
}
self.tableView.panGestureRecognizer.enabled = YES;
}
Il codice completo per il test di cui sopra
//
// LBPangestureController.m
// TEXT
//
// Created by mac on 2024/7/7.
// Copyright © 2024 刘博. All rights reserved.
//
#import "LBPangestureController.h"
@interface LBPangestureController () <UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIPanGestureRecognizer *pangesture;
@property (nonatomic, assign) NSInteger panNum;
@end
@implementation LBPangestureController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.tableView];
[self.view addGestureRecognizer:self.pangesture];
// Do any additional setup after loading the view.
}
- (void)handlePan:(UIPanGestureRecognizer *)pan
{
self.tableView.panGestureRecognizer.enabled = YES;
NSLog(@"哈哈哈哈哈这是第%ld次响应滑动手势handlePan 方法", self.panNum);
if (self.panNum % 2 == 0) {
self.tableView.panGestureRecognizer.enabled = NO;
} else {
self.tableView.panGestureRecognizer.enabled = YES;
}
self.tableView.panGestureRecognizer.enabled = YES;
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
cell.textLabel.text = [NSString stringWithFormat:@"%ld", indexPath.row];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 100;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60;
}
#pragma mark - uiscrollViewdelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"哈哈哈哈哈这里是执行scrollViewDidScroll self.panNum是%ld", self.panNum);
}
#pragma mark - gesturedelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer == self.pangesture) {
self.panNum ++;
}
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (gestureRecognizer == self.pangesture && otherGestureRecognizer == self.tableView.panGestureRecognizer) {
return YES;
}
return NO;
}
#pragma mark - lazy load
- (UITableView *)tableView
{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, 300, 400) style:UITableViewStylePlain];
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor cyanColor];
}
return _tableView;
}
- (UIPanGestureRecognizer *)pangesture
{
if (!_pangesture) {
_pangesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
_pangesture.delegate = self;
}
return _pangesture;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end