-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathMTViewController.m
More file actions
82 lines (69 loc) · 2.26 KB
/
MTViewController.m
File metadata and controls
82 lines (69 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// MTViewController.m
// iosMathEditor
//
// Created by Kostub Deshmukh on 05/13/2016.
// Copyright (C) 2016 Kostub Deshmukh
//
// This software may be modified and distributed under the terms of the
// MIT license. See the LICENSE file for details.
//
#import "MTViewController.h"
@import MathKeyboard;
@interface MTViewController () <MTEditableMathLabelDelegate>
@end
@implementation MTViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.mathLabel.layer.borderColor = [UIColor blackColor].CGColor;
self.mathLabel.layer.borderWidth = 2;
self.mathLabel.layer.cornerRadius = 5;
self.mathLabel.keyboard = [MTMathKeyboardRootView sharedInstance];
self.mathLabel.delegate = self;
[self.mathLabel enableTap:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark MTEditableMathLabelDelegate
- (void)textModified:(MTEditableMathLabel *)label
{
CGFloat minHeight = 64;
// Increase the height of the label as the height increases.
CGSize mathSize = label.mathDisplaySize;
if (mathSize.height > self.labelHeight.constant - 10) {
[label layoutIfNeeded];
// animate
[UIView animateWithDuration:0.5 animations:^{
self.labelHeight.constant = mathSize.height + 10;
[label layoutIfNeeded];
}];
} else if (mathSize.height < self.labelHeight.constant - 20) {
CGFloat newHeight = MAX(mathSize.height + 10, minHeight);
if (newHeight < self.labelHeight.constant) {
[label layoutIfNeeded];
// animate
[UIView animateWithDuration:0.5 animations:^{
self.labelHeight.constant = newHeight;
[label layoutIfNeeded];
}];
}
}
// Shrink the font as the label gets longer.
if (mathSize.width > label.frame.size.width - 10) {
label.fontSize = label.fontSize * 0.9;
} else if (mathSize.width < label.frame.size.width - 40) {
CGFloat fontSize = MIN(label.fontSize * 1.1, 30);
if (fontSize > label.fontSize) {
label.fontSize = fontSize;
}
}
}
- (void)didBeginEditing:(MTEditableMathLabel *)label
{
self.placeholderLabel.hidden = YES;
}
@end