Class Overriding
Substitute our hierarchy with our own Views
Face SDK provides you a way to register a custom subclass in place of our internal view class with 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 Overriding protocol.

LivenessContentView

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 setupConstraints method with your own constraints.
Swift
Objective-C
1
final class MyLivenessContent: LivenessContentView {
2
override func setupConstraints() {
3
// Pin ToolbarView to the top of the content.
4
toolbarView.translatesAutoresizingMaskIntoConstraints = false
5
NSLayoutConstraint.activate([
6
toolbarView.leadingAnchor.constraint(equalTo: leadingAnchor),
7
toolbarView.trailingAnchor.constraint(equalTo: trailingAnchor),
8
toolbarView.topAnchor.constraint(equalTo: topAnchor),
9
])
10
11
// Leave HintView default constraints
12
hintView.translatesAutoresizingMaskIntoConstraints = false
13
let centerConstraint = NSLayoutConstraint(
14
item: hintView, attribute: .centerY,
15
relatedBy: .equal,
16
toItem: self, attribute: .centerY,
17
multiplier: 0.68, constant: 0
18
);
19
NSLayoutConstraint.activate([
20
hintView.leadingAnchor.constraint(greaterThanOrEqualTo: self.leadingAnchor, constant: 8),
21
hintView.trailingAnchor.constraint(lessThanOrEqualTo: self.trailingAnchor, constant: -8),
22
23
hintView.centerXAnchor.constraint(equalTo: self.centerXAnchor),
24
centerConstraint,
25
])
26
}
27
}
Copied!
1
// MyLivenessContent.h
2
3
#import <UIKit/UIKit.h>
4
5
@class RFSLivenessContentView;
6
7
@interface MyLivenessContent : RFSLivenessContentView
8
@end
9
10
// MyLivenessContent.m
11
12
#import <FaceSDK/FaceSDK.h>
13
14
@implementation MyLivenessContent
15
16
- (void)setupConstraints {
17
self.toolbarView.translatesAutoresizingMaskIntoConstraints = NO;
18
[NSLayoutConstraint activateConstraints:@[
19
[self.toolbarView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
20
[self.toolbarView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
21
[self.toolbarView.topAnchor constraintEqualToAnchor:self.topAnchor],
22
]];
23
24
self.hintView.translatesAutoresizingMaskIntoConstraints = NO;
25
NSLayoutConstraint *centerConstraint =
26
[NSLayoutConstraint constraintWithItem:self.hintView attribute:NSLayoutAttributeCenterY
27
relatedBy:NSLayoutRelationEqual
28
toItem:self attribute:NSLayoutAttributeCenterY
29
multiplier:0.68 constant:0];
30
[NSLayoutConstraint activateConstraints:@[
31
[self.hintView.leadingAnchor constraintGreaterThanOrEqualToAnchor:self.leadingAnchor constant:8],
32
[self.hintView.trailingAnchor constraintLessThanOrEqualToAnchor:self.trailingAnchor constant:-8],
33
34
[self.hintView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
35
centerConstraint,
36
]];
37
}
38
39
@end
Copied!
Please note that we do not call super in the 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!
Swift
Objective-C
1
let configuration = LivenessConfiguration {
2
$0.registerClass(MyLivenessContent.self, forBaseClass: LivenessContentView.self)
3
}
4
5
FaceSDK.service.startLiveness(
6
from: viewController,
7
animated: true,
8
configuration: configuration,
9
onLiveness: { response in
10
// ... check response.liveness for detection result.
11
},
12
completion: nil
13
)
Copied!
1
RFSLivenessConfiguration *configuration = [RFSLivenessConfiguration configurationWithBuilder:^(RFSLivenessConfigurationBuilder * _Nonnull builder) {
2
[builder registerClass:MyLivenessContent.class forBaseClass:RFSLivenessContentView.class];
3
}];
4
5
[RFSFaceSDK.service startLivenessFrom:viewController
6
animated:YES
7
configuration:configuration
8
onLiveness:^(RFSLivenessResponse * _Nonnull response) {
9
// ... check response.liveness for detection result.
10
} completion:nil];
Copied!
The ToolbarView pinned to the top of Liveness UI
For more Class Overriding examples please take a look at our Catalog App. If you need more information about supported Overriding classes and documentation see our SDK Reference.
Last modified 4mo ago
Copy link