How to hide shadows in UITableViewCell when cell is dragging

一笑奈何 提交于 2021-01-27 04:41:01

问题


I have UITableView with hided separator line, and when I dragging cell, shadows appears some kind as borders comes out on up and down. How to hide this? Please see example: Emulator screenshot

Great thanks!


回答1:


So, I have answer, just subclass of UITableView with method:

- (void) didAddSubview:(UIView *)subview
{
    [super didAddSubview:subview];

    if([subview.class.description isEqualToString:@"UIShadowView"]) {
        subview.hidden = YES;
    }
}



回答2:


NoShadowTableView.m

#import "NoShadowTableView.h"

@interface NoShadowTableView ()
{
    //  iOS7
    __weak UIView* wrapperView;
}

@end

@implementation NoShadowTableView

- (void) didAddSubview:(UIView *)subview
{
    [super didAddSubview:subview];

    //  iOS7
    if(wrapperView == nil && [[[subview class] description] isEqualToString:@"UITableViewWrapperView"])
        wrapperView = subview;

    //  iOS6
    if([[[subview class] description] isEqualToString:@"UIShadowView"])
        [subview setHidden:YES];
}

- (void) layoutSubviews
{
    [super layoutSubviews];

    //  iOS7
    for(UIView* subview in wrapperView.subviews)
    {
        if([[[subview class] description] isEqualToString:@"UIShadowView"])
            [subview setHidden:YES];
    }
}

@end



回答3:


This code works for me!

import UIKit

class NoShadowTableView: UITableView {

    override func didAddSubview(_ subview: UIView) {
        super.didAddSubview(subview)
        if "\(type(of: subview))" == "UIShadowView" {
            subview.removeFromSuperview()
        }
    }

}



回答4:


I was facing a similar problem by using default UITableView reordering controls. So I used this external third-party library which solved my problem.

https://github.com/shusta/ReorderingTableViewController

Hope this helps




回答5:


Swift 3 implementation (removed iOS6 support)

import UIKit

class NoShadowTableView: UITableView {

    weak var wrapperView: UIView?

    override func didAddSubview(_ subview: UIView) {
        super.didAddSubview(subview)

        if wrapperView == nil && "\(type(of: subview))" == "UITableViewWrapperView" {
            wrapperView = subview
        }
    }

    override func layoutSubviews() {
        super.layoutSubviews()

        wrapperView?.subviews.forEach({ view in
            if "\(type(of: view))" == "UIShadowView" {
                view.isHidden = true
            }
        })
    }
}



回答6:


Quick hack is subclassing UITableViewCell and add method:

 override func layoutSubviews() {
        super.layoutSubviews()

        superview?.subviews.filter({ "\(type(of: $0))" == "UIShadowView" }).forEach { (sv: UIView) in
            sv.removeFromSuperview()
        }
    }



回答7:


For me hacks with the UIShadowView didn't work. I checked the solution on iOS 10. But one line in a cell class has done the trick:

override func layoutSubviews() {
    super.layoutSubviews()
    self.subviews.filter{ $0 is UIImageView }.forEach { $0.isHidden = true }
}



回答8:


Swift 4 solution; use extended uitableviewcontroller because now shadow is in the table and only added when cell is moved.

class UITableViewControllerEx: UITableViewController {

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        view.subviews.filter({ String(describing: type(of: $0)) == "UIShadowView" }).forEach { (sv: UIView) in
            sv.isHidden = true
        }
    }

}


来源:https://stackoverflow.com/questions/14607068/how-to-hide-shadows-in-uitableviewcell-when-cell-is-dragging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!