The textInput used to flicker on IOS 8 when its content size was greater than its frame.

This commit is contained in:
ylecollen 2015-01-15 16:18:12 +01:00
parent 380872b2ac
commit 7c5ad70897
4 changed files with 93 additions and 2 deletions

View file

@ -329,7 +329,7 @@
<action selector="onButtonPressed:" destination="msb-ol-2LB" eventType="touchUpInside" id="YtT-Cb-ZPk"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UVo-EY-Nyg" customClass="HPGrowingTextView">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UVo-EY-Nyg" customClass="ConsoleGrowingTextView">
<rect key="frame" x="38" y="8" width="510" height="28"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Icg-kc-a2c">

View file

@ -0,0 +1,21 @@
/*
Copyright 2014 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <MatrixSDK/MatrixSDK.h>
#import "HPGrowingTextView.h"
@interface ConsoleGrowingTextView : HPGrowingTextView
@end

View file

@ -0,0 +1,67 @@
/*
Copyright 2014 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import "ConsoleGrowingTextView.h"
@implementation ConsoleGrowingTextView
// override theses two methods to fix a weird IOS 8 issue
// it seems that the textview must be a little smaller than its superview
// else when MaxHeght is reached, the text scrolls up because setContentSize is called
// 1 - with a wrong contentSize < frame height so scroll to the top
// 2 - with the right content : resetScrollPositionForIOS7 fix the content Offset
// so center the textView in its superView
-(void)resizeTextView:(NSInteger)newSizeH
{
if ([delegate respondsToSelector:@selector(growingTextView:willChangeHeight:)]) {
[delegate growingTextView:self willChangeHeight:newSizeH + self.layer.cornerRadius];
}
CGRect internalTextViewFrame = self.frame;
internalTextViewFrame.size.height = newSizeH + self.layer.cornerRadius; // + padding
self.frame = internalTextViewFrame;
internalTextViewFrame.size.height = newSizeH - self.layer.cornerRadius;
internalTextViewFrame.origin.y = contentInset.top - contentInset.bottom;
internalTextViewFrame.origin.x = contentInset.left;
if(!CGRectEqualToRect(self.internalTextView.frame, internalTextViewFrame)) {
self.internalTextView.frame = internalTextViewFrame;
}
}
-(void)layoutSubviews
{
[super layoutSubviews];
CGRect r = self.bounds;
r.origin.y = 0;
r.origin.x = contentInset.left;
r.size.width -= contentInset.left + contentInset.right;
if (self.hasText) {
r.origin.y += self.layer.cornerRadius / 2;
r.size.height -= self.layer.cornerRadius;
}
if (!CGRectEqualToRect(r, self.internalTextView.frame )) {
self.internalTextView.frame = r;
}
}
@end

View file

@ -31,6 +31,8 @@
#import "MediaManager.h"
#import "ConsoleTools.h"
#import "ConsoleGrowingTextView.h"
#define ROOMVIEWCONTROLLER_TYPING_TIMEOUT_SEC 10
#define ROOMVIEWCONTROLLER_UPLOAD_FILE_SIZE 5000000
@ -114,7 +116,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
@property (weak, nonatomic) IBOutlet UITableView *messagesTableView;
@property (weak, nonatomic) IBOutlet UIView *controlView;
@property (weak, nonatomic) IBOutlet UIButton *optionBtn;
@property (weak, nonatomic) IBOutlet HPGrowingTextView *messageTextView;
@property (weak, nonatomic) IBOutlet ConsoleGrowingTextView *messageTextView;
@property (weak, nonatomic) IBOutlet UIButton *sendBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *messagesTableViewBottomConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *controlViewBottomConstraint;
@ -174,6 +176,7 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
self.messageTextView.layer.borderWidth = 1;
self.messageTextView.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.messageTextView.clipsToBounds = YES;
self.messageTextView.backgroundColor = [UIColor whiteColor];
lastEditedText = self.messageTextView.text;
}