Skip to content

Commit

Permalink
Reply from developer.apple.com
Browse files Browse the repository at this point in the history
  • Loading branch information
layik committed Apr 6, 2019
1 parent d9947f7 commit dce74a3
Showing 1 changed file with 32 additions and 40 deletions.
72 changes: 32 additions & 40 deletions keyboard/KeyboardViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,60 @@
// KeyboardViewController.m
// keyboard
//
// Created by layik on 02/04/2019.
// Copyright © 2019 layik. All rights reserved.
// Created by Ziqiao Chen on 9/14/15.
// Copyright (c) 2015 Ziqiao Chen. All rights reserved.
//

#import "KeyboardViewController.h"

@interface KeyboardViewController ()

@property (nonatomic, strong) UIButton *nextKeyboardButton;
@property (nonatomic, strong) UIView *keysView;
@property (nonatomic, strong) NSLayoutConstraint *keyboardHeightConstraint;

@end

@implementation KeyboardViewController

- (void)updateViewConstraints {
[super updateViewConstraints];

// Add custom view sizing constraints here
NSLayoutConstraint *heightConstraint =
[NSLayoutConstraint constraintWithItem: self.view
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 0.0
constant: 300];
[self.view addConstraint: heightConstraint];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(91, 15, 120, 25)];
label.text = [NSString stringWithFormat:@"%f", self.view.frame.size.height];
[self.view addSubview:label];
}
- (void)viewDidLoad {
[super viewDidLoad];

// Perform custom UI setup here
self.keysView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

self.keyboardHeightConstraint = [NSLayoutConstraint constraintWithItem:self.view
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:0.0
constant:310];
[self.keyboardHeightConstraint setPriority:UILayoutPriorityDefaultHigh];
[self.view addConstraints:@[self.keyboardHeightConstraint]];

self.nextKeyboardButton = [UIButton buttonWithType:UIButtonTypeSystem];

[self.nextKeyboardButton setTitle:NSLocalizedString(@"Next Keyboard", @"Title for 'Next Keyboard' button") forState:UIControlStateNormal];
[self.nextKeyboardButton sizeToFit];
self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = NO;

[self.nextKeyboardButton addTarget:self action:@selector(handleInputModeListFromView:withEvent:) forControlEvents:UIControlEventAllTouchEvents];
[self.nextKeyboardButton addTarget:self action:@selector(advanceToNextInputMode) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:self.nextKeyboardButton];
}

- (void)textWillChange:(id<UITextInput>)textInput {
// The app is about to change the document's contents. Perform any preparation here.
[self.keysView addSubview:self.nextKeyboardButton];

NSLayoutConstraint *nextKeyboardButtonLeftSideConstraint = [NSLayoutConstraint constraintWithItem:self.nextKeyboardButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.keysView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0];
NSLayoutConstraint *nextKeyboardButtonBottomConstraint = [NSLayoutConstraint constraintWithItem:self.nextKeyboardButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.keysView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
[self.keysView addConstraints:@[nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint]];

self.keysView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
[self.view addSubview:self.keysView];
}

- (void)textDidChange:(id<UITextInput>)textInput {
// The app has just changed the document's contents, the document context has been updated.
- (void)dealloc {

UIColor *textColor = nil;
if (self.textDocumentProxy.keyboardAppearance == UIKeyboardAppearanceDark) {
textColor = [UIColor whiteColor];
} else {
textColor = [UIColor blackColor];
}
[self.nextKeyboardButton setTitleColor:textColor forState:UIControlStateNormal];
self.keysView = nil;
self.keyboardHeightConstraint = nil;
self.nextKeyboardButton = nil;
}

@end

0 comments on commit dce74a3

Please sign in to comment.