Skip to content

Class Overriding

The Face SDK provides a way to register a custom subclass in place of our internal view class with the registerClass(Overriding.Type, forBaseClass: Overriding.Type) API.

This allows you to take more control of what is being displayed to the user. For example, with a custom subclass in our UI module hierarchy, you can react to various life-cycle methods and make changes you want!


The views that support overriding are marked with the Overriding protocol.


Here is how you can use this method to customize the layout appearance of the Liveness process.

Suppose you want to move the CameraToolBarView to the top of the screen. For this, you simply need to create your own subclass of the LivenessContentView and provide the setupConstraints method with your own constraints.

final class MyLivenessContent: LivenessContentView {
    override func setupConstraints() {
        // Pin ToolbarView to the top of the content.
        toolbarView.translatesAutoresizingMaskIntoConstraints = false
            toolbarView.leadingAnchor.constraint(equalTo: leadingAnchor),
            toolbarView.trailingAnchor.constraint(equalTo: trailingAnchor),
            toolbarView.topAnchor.constraint(equalTo: topAnchor),

        // Leave HintView default constraints
        hintView.translatesAutoresizingMaskIntoConstraints = false
        let centerConstraint = NSLayoutConstraint(
            item: hintView, attribute: .centerY,
            relatedBy: .equal,
            toItem: self, attribute: .centerY,
            multiplier: 0.68, constant: 0
            hintView.leadingAnchor.constraint(greaterThanOrEqualTo: self.leadingAnchor, constant: 8),
            hintView.trailingAnchor.constraint(lessThanOrEqualTo: self.trailingAnchor, constant: -8),

            hintView.centerXAnchor.constraint(equalTo: self.centerXAnchor),
// MyLivenessContent.h

#import <UIKit/UIKit.h>

@class RFSLivenessContentView;

@interface MyLivenessContent : RFSLivenessContentView

// MyLivenessContent.m

#import <FaceSDK/FaceSDK.h>

@implementation MyLivenessContent

- (void)setupConstraints {
    self.toolbarView.translatesAutoresizingMaskIntoConstraints = NO;
    [NSLayoutConstraint activateConstraints:@[
        [self.toolbarView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
        [self.toolbarView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
        [self.toolbarView.topAnchor constraintEqualToAnchor:self.topAnchor],

    self.hintView.translatesAutoresizingMaskIntoConstraints = NO;
    NSLayoutConstraint *centerConstraint =
    [NSLayoutConstraint constraintWithItem:self.hintView attribute:NSLayoutAttributeCenterY
                                    toItem:self attribute:NSLayoutAttributeCenterY
                                multiplier:0.68 constant:0];
    [NSLayoutConstraint activateConstraints:@[
        [self.hintView.leadingAnchor constraintGreaterThanOrEqualToAnchor:self.leadingAnchor constant:8],
        [self.hintView.trailingAnchor constraintLessThanOrEqualToAnchor:self.trailingAnchor constant:-8],

        [self.hintView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],



Please note that we do not call super in this example. We do not want the constraints to conflict with the default ones.

After declaring this custom subclass, all we have to do is register it in the LivenessConfiguration and that's it!

let configuration = LivenessConfiguration {
    $0.registerClass(MyLivenessContent.self, forBaseClass: LivenessContentView.self)

    from: viewController,
    animated: true, 
    configuration: configuration,
    onLiveness: { response in
        // ... check response.liveness for detection result.
    completion: nil
RFSLivenessConfiguration *configuration = [RFSLivenessConfiguration configurationWithBuilder:^(RFSLivenessConfigurationBuilder  * _Nonnull builder) {
[builder registerClass:MyLivenessContent.class forBaseClass:RFSLivenessContentView.class];

[RFSFaceSDK.service startLivenessFrom:viewController
                        onLiveness:^(RFSLivenessResponse * _Nonnull response) {
// ... check response.liveness for detection result.
} completion:nil];


For more Class Overriding examples, please take a look at the Catalog App. If you need more information about the supported Overriding classes and documentation, see SDK Reference.