Fix chat scroll bug

Fix background glitches when rotating the device
Fix Contacts remove button bug
This commit is contained in:
Yann Diorcet 2012-08-01 12:37:38 +02:00
parent 52a2f5bade
commit 511cab00c6
29 changed files with 287 additions and 575 deletions

View file

@ -45,7 +45,8 @@
}
}
#pragma mark -
#pragma mark -
- (void)loadData {
if(data != nil) {

View file

@ -35,6 +35,7 @@
@synthesize footerView;
@synthesize fieldBackgroundImage;
#pragma mark - Lifecycle Functions
- (id)init {
@ -300,19 +301,33 @@ static UICompositeViewDescription *compositeDescription = nil;
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:TRUE];
if(UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
int width = endFrame.size.height;
endFrame.size.height = endFrame.size.width;
endFrame.size.width = width;
}
// Move view
CGRect frame = [[self view] frame];
frame.origin.y = [self.view convertPoint:endFrame.origin fromView:nil].y - frame.size.height;
[[self view] setFrame:frame];
{
CGRect frame = [[self view] frame];
CGRect rect = [PhoneMainView instance].view.bounds;
CGPoint pos = {frame.size.width, frame.size.height};
CGPoint gPos = [self.view convertPoint:pos toView:[UIApplication sharedApplication].keyWindow.rootViewController.view]; // Bypass IOS bug on landscape mode
frame.origin.y = (rect.size.height - gPos.y - endFrame.size.height);
if(frame.origin.y > 0) frame.origin.y = 0;
[[self view] setFrame:frame];
}
// Resize table view
CGPoint pos = {0, 0};
CGPoint gPos = [[self.view superview] convertPoint:pos toView:self.view];
CGRect tableFrame = [tableController.view frame];
tableFrame.origin.y = gPos.y;
tableFrame.size.height = [footerView frame].origin.y - tableFrame.origin.y;
[tableController.view setFrame:tableFrame];
{
CGPoint pos = {0, 0};
CGPoint gPos = [[self.view superview] convertPoint:pos toView:self.view];
CGRect tableFrame = [tableController.view frame];
tableFrame.origin.y = gPos.y;
tableFrame.size.height = [footerView frame].origin.y - tableFrame.origin.y;
[tableController.view setFrame:tableFrame];
}
// Scroll
int lastSection = [tableController.tableView numberOfSections] -1;

View file

@ -253,6 +253,7 @@
<string key="NSFrame">{{250, 0}, {70, 59}}</string>
<reference key="NSSuperview" ref="833509359"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<object class="IBUIAccessibilityConfiguration" key="IBUIAccessibilityConfiguration">

View file

@ -534,6 +534,7 @@
}
[headerController setEditing:editing animated:animated];
[footerController setEditing:editing animated:animated];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

View file

@ -57,6 +57,7 @@
#pragma mark -
- (void)resetData {
[self disableEdit:FALSE];
if(contact == NULL) {
ABAddressBookRevert(addressBook);
return;
@ -190,7 +191,6 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
[self resetData];
self->contact = ABAddressBookGetPersonWithRecordID(addressBook, ABRecordGetRecordID(acontact));
[tableController setContact:self->contact];
[self disableEdit:FALSE];
}

View file

@ -176,6 +176,7 @@
<string key="NSFrame">{{0, 59}, {320, 401}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">10</int>
@ -449,7 +450,6 @@ AAgACAAIAAEAAQABAAE</bytes>
<string key="-2.CustomClassName">UIResponder</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="19.CustomClassName">TPKeyboardAvoidingTableView</string>
<string key="19.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="20.CustomClassName">ContactDetailsTableViewController</string>
<string key="20.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@ -530,14 +530,6 @@ AAgACAAIAAEAAQABAAE</bytes>
<string key="minorKey">./Classes/ContactDetailsViewController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">TPKeyboardAvoidingTableView</string>
<string key="superclassName">UITableView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/TPKeyboardAvoidingTableView.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UIToggleButton</string>
<string key="superclassName">UIButton</string>

View file

@ -82,12 +82,16 @@
ABMultiValueRef lMap = ABRecordCopyValue((ABRecordRef)lPerson, kABPersonInstantMessageProperty);
for(int i = 0; i < ABMultiValueGetCount(lMap); ++i) {
CFDictionaryRef lDict = ABMultiValueCopyValueAtIndex(lMap, i);
if(CFDictionaryContainsKey(lDict, @"service")) {
if(CFStringCompare((CFStringRef)@"SIP", CFDictionaryGetValue(lDict, @"service"), kCFCompareCaseInsensitive) == 0) {
if(CFDictionaryContainsKey(lDict, kABPersonInstantMessageServiceKey)) {
CFStringRef serviceKey = CFDictionaryGetValue(lDict, kABPersonInstantMessageServiceKey);
if(CFStringCompare((CFStringRef)@"SIP", serviceKey, kCFCompareCaseInsensitive) == 0) {
add = true;
}
} else {
add = true;
NSString* usernameKey = CFDictionaryGetValue(lDict, kABPersonInstantMessageUsernameKey);
if([usernameKey hasPrefix:@"sip:"]) {
add = true;
}
}
CFRelease(lDict);
}

View file

@ -413,8 +413,8 @@
</object>
<object class="IBUIButton" id="614750242">
<reference key="NSNextResponder" ref="581237105"/>
<int key="NSvFlags">269</int>
<string key="NSFrame">{{33, 273}, {255, 50}}</string>
<int key="NSvFlags">293</int>
<string key="NSFrame">{{33, 323}, {255, 50}}</string>
<reference key="NSSuperview" ref="581237105"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
@ -610,10 +610,10 @@
<array class="NSMutableArray" key="children">
<reference ref="136975389"/>
<reference ref="768037913"/>
<reference ref="614750242"/>
<reference ref="943502497"/>
<reference ref="244755503"/>
<reference ref="310438316"/>
<reference ref="614750242"/>
</array>
<reference key="parent" ref="0"/>
</object>

View file

@ -302,34 +302,38 @@ static UICompositeViewDescription *compositeDescription = nil;
hideControlsTimer = nil;
}
// show controls
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[[PhoneMainView instance] showTabBar: true];
[videoCameraSwitch setAlpha:1.0];
[UIView commitAnimations];
// hide controls in 5 sec
hideControlsTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(hideControls:)
userInfo:nil
repeats:NO];
if([[[PhoneMainView instance] currentView] equal:[InCallViewController compositeViewDescription]] && videoShown) {
// show controls
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[[PhoneMainView instance] showTabBar: true];
[videoCameraSwitch setAlpha:1.0];
[UIView commitAnimations];
// hide controls in 5 sec
hideControlsTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(hideControls:)
userInfo:nil
repeats:NO];
}
}
- (void)hideControls:(id)sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[videoCameraSwitch setAlpha:0.0];
[UIView commitAnimations];
if([[[PhoneMainView instance] currentView] equal:[InCallViewController compositeViewDescription]] && videoShown)
[[PhoneMainView instance] showTabBar: false];
if (hideControlsTimer) {
[hideControlsTimer invalidate];
hideControlsTimer = nil;
}
if([[[PhoneMainView instance] currentView] equal:[InCallViewController compositeViewDescription]] && videoShown) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[videoCameraSwitch setAlpha:0.0];
[UIView commitAnimations];
[[PhoneMainView instance] showTabBar: false];
}
}
#ifdef TEST_VIDEO_VIEW_CHANGE

View file

@ -42,6 +42,7 @@
<string key="NSFrameSize">{320, 480}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MAA</bytes>
@ -49,9 +50,11 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIVisibleAtLaunch">YES</bool>
<bool key="IBUIResizesToFullScreen">YES</bool>
</object>
<object class="IBUIViewController" id="110348778">
<bool key="IBUIAutoresizesArchivedViewToFullSize">NO</bool>
<string key="IBUINibName">PhoneMainView</string>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="IBUIInterfaceOrientation">1</int>
@ -132,6 +135,7 @@
<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="-2.CustomClassName">UIResponder</string>
<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="2.CustomClassName">UILinphoneWindow</string>
<dictionary class="NSMutableDictionary" key="2.IBAttributePlaceholdersKey"/>
<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="4.CustomClassName">LinphoneAppDelegate</string>
@ -234,6 +238,14 @@
<string key="minorKey">./Classes/UICompositeViewController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UILinphoneWindow</string>
<string key="superclassName">UIWindow</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/UILinphoneWindow.h</string>
</object>
</object>
</array>
</object>
<int key="IBDocument.localizationMode">0</int>

View file

@ -23,6 +23,10 @@
#import "LinphoneCoreSettingsStore.h"
@interface UILinphoneWindow : UIWindow
@end
@interface LinphoneAppDelegate : NSObject <UIApplicationDelegate,UIAlertViewDelegate> {
UIWindow *window;
CTCallCenter* callCenter;

View file

@ -38,6 +38,10 @@ int __aeabi_idiv(int a, int b) {
}
#endif
@implementation UILinphoneWindow
@end
@implementation LinphoneAppDelegate
@synthesize window;
@ -161,7 +165,6 @@ int __aeabi_idiv(int a, int b) {
}
- (void)setupUI {
if ([[LinphoneManager instance].settingsStore boolForKey:@"enable_first_login_view_preference"] == true) {
// Change to fist login view
[[PhoneMainView instance] changeCurrentView: [FirstLoginViewController compositeViewDescription]];

View file

@ -497,10 +497,10 @@
<object class="IBUIView" id="259467918">
<reference key="NSNextResponder" ref="143533231"/>
<int key="NSvFlags">290</int>
<string key="NSFrame">{{0, 100}, {320, 2000}}</string>
<string key="NSFrame">{{0, 135}, {320, 2000}}</string>
<reference key="NSSuperview" ref="143533231"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="99607181"/>
<reference key="NSNextKeyView" ref="1070539677"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
@ -714,7 +714,7 @@
<string key="NSFrame">{{0, 67}, {105, 68}}</string>
<reference key="NSSuperview" ref="143533231"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="259467918"/>
<reference key="NSNextKeyView" ref="99607181"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<int key="IBUITag">25</int>
@ -774,7 +774,7 @@
<string key="NSFrame">{{215, 67}, {105, 68}}</string>
<reference key="NSSuperview" ref="143533231"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1070539677"/>
<reference key="NSNextKeyView" ref="259467918"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<int key="IBUITag">27</int>
@ -1193,7 +1193,7 @@
<object class="IBUIView" id="298889112">
<reference key="NSNextResponder" ref="950460796"/>
<int key="NSvFlags">290</int>
<string key="NSFrame">{{0, 50}, {480, 2000}}</string>
<string key="NSFrame">{{0, 82}, {480, 2000}}</string>
<reference key="NSSuperview" ref="950460796"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="102684796"/>

View file

@ -117,35 +117,6 @@ static UIFont *CELL_FONT = nil;
}
}
- (void)resizeContent {
if(chat != nil) {
// Resize Content
CGRect contentFrame = [contentView frame];
contentFrame.size = [UIChatRoomCell viewSize:[chat message] width:[self frame].size.width];
if([[chat direction] intValue]) { // Inverted
contentFrame.origin.x = 0.0f;
contentFrame.origin.y = 0.0f;
} else {
contentFrame.origin.x = [self frame].size.width - contentFrame.size.width;
contentFrame.origin.y = 0.0f;
}
[contentView setFrame:contentFrame];
CGRect messageFrame = [messageView frame];
messageFrame.origin.y = ([contentView frame].size.height - messageFrame.size.height)/2;
if([[chat direction] intValue]) { // Inverted
[backgroundImage setImage:[TUNinePatchCache imageOfSize:[backgroundImage bounds].size
forNinePatchNamed:@"chat_bubble_incoming"]];
messageFrame.origin.y += 5;
} else {
[backgroundImage setImage:[TUNinePatchCache imageOfSize:[backgroundImage bounds].size
forNinePatchNamed:@"chat_bubble_outgoing"]];
messageFrame.origin.y -= 5;
}
[messageView setFrame:messageFrame];
}
}
+ (CGSize)viewSize:(NSString*)message width:(int)width {
if(CELL_FONT == nil) {
CELL_FONT = [UIFont systemFontOfSize:CELL_FONT_SIZE];
@ -171,7 +142,32 @@ static UIFont *CELL_FONT = nil;
- (void)layoutSubviews {
[super layoutSubviews];
[self resizeContent];
if(chat != nil) {
// Resize Content
CGRect contentFrame = [contentView frame];
contentFrame.size = [UIChatRoomCell viewSize:[chat message] width:[self frame].size.width];
if([[chat direction] intValue]) { // Inverted
contentFrame.origin.x = 0.0f;
contentFrame.origin.y = 0.0f;
} else {
contentFrame.origin.x = [self frame].size.width - contentFrame.size.width;
contentFrame.origin.y = 0.0f;
}
[contentView setFrame:contentFrame];
CGRect messageFrame = [messageView frame];
messageFrame.origin.y = ([contentView frame].size.height - messageFrame.size.height)/2;
if([[chat direction] intValue]) { // Inverted
[backgroundImage setImage:[TUNinePatchCache imageOfSize:[backgroundImage bounds].size
forNinePatchNamed:@"chat_bubble_incoming"]];
messageFrame.origin.y += 5;
} else {
[backgroundImage setImage:[TUNinePatchCache imageOfSize:[backgroundImage bounds].size
forNinePatchNamed:@"chat_bubble_outgoing"]];
messageFrame.origin.y -= 5;
}
[messageView setFrame:messageFrame];
}
}

View file

@ -3,19 +3,19 @@
<data>
<int key="IBDocument.SystemTarget">1296</int>
<string key="IBDocument.SystemVersion">11E53</string>
<string key="IBDocument.InterfaceBuilderVersion">2182</string>
<string key="IBDocument.InterfaceBuilderVersion">2549</string>
<string key="IBDocument.AppKitVersion">1138.47</string>
<string key="IBDocument.HIToolboxVersion">569.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">1181</string>
<string key="NS.object.0">1498</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBProxyObject</string>
<string>IBUIButton</string>
<string>IBUIImageView</string>
<string>IBUIView</string>
<string>IBUILabel</string>
<string>IBProxyObject</string>
<string>IBUIView</string>
</array>
<array key="IBDocument.PluginDependencies">
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@ -35,7 +35,7 @@
</object>
<object class="IBUIView" id="579600281">
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<int key="NSvFlags">301</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUIImageView" id="340144998">
<reference key="NSNextResponder" ref="579600281"/>
@ -181,17 +181,21 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="369753676">
<nil key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{100, 100}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="765717609"/>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="111268450">
<nil key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{100, 100}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="765717609"/>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
@ -443,6 +447,6 @@
<string key="list_delete_default.png">{45, 45}</string>
<string key="list_delete_over.png">{45, 45}</string>
</dictionary>
<string key="IBCocoaTouchPluginVersion">1181</string>
<string key="IBCocoaTouchPluginVersion">1498</string>
</data>
</archive>

View file

@ -19,6 +19,8 @@
#import "UICompositeViewController.h"
#import "PhoneMainView.h"
@implementation UICompositeViewDescription
@synthesize name;
@ -90,7 +92,7 @@
#pragma mark - Lifecycle Functions
- (void)initUICompositeViewController {
self->viewControllerCache = [[NSMutableDictionary alloc] init];
self->viewControllerCache = [[NSMutableDictionary alloc] init];
self->currentOrientation = UIDeviceOrientationUnknown;
}
@ -148,13 +150,8 @@
[contentViewController viewWillAppear:animated];
[tabBarViewController viewWillAppear:animated];
[stateBarViewController viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//currentOrientation = [UIDevice currentDevice].orientation;
currentOrientation = [[UIDevice currentDevice] orientation];
}
- (void)viewDidAppear:(BOOL)animated {
@ -171,9 +168,6 @@
[stateBarViewController viewWillDisappear:animated];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)viewDidDisappear:(BOOL)animated {
@ -183,24 +177,19 @@
[stateBarViewController viewDidDisappear:animated];
}
- (void)orientationChanged:(NSNotification *)notification {
currentOrientation = [[UIDevice currentDevice] orientation];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
UIDeviceOrientation correctOrientation = [self getCorrectInterfaceOrientation:toInterfaceOrientation];
[super willRotateToInterfaceOrientation:correctOrientation duration:duration];
[contentViewController willRotateToInterfaceOrientation:correctOrientation duration:duration];
[tabBarViewController willRotateToInterfaceOrientation:correctOrientation duration:duration];
[stateBarViewController willRotateToInterfaceOrientation:correctOrientation duration:duration];
currentOrientation = [self getCorrectInterfaceOrientation:toInterfaceOrientation];
[super willRotateToInterfaceOrientation:currentOrientation duration:duration];
[contentViewController willRotateToInterfaceOrientation:currentOrientation duration:duration];
[tabBarViewController willRotateToInterfaceOrientation:currentOrientation duration:duration];
[stateBarViewController willRotateToInterfaceOrientation:currentOrientation duration:duration];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
UIDeviceOrientation correctOrientation = [self getCorrectInterfaceOrientation:toInterfaceOrientation];
[super willAnimateRotationToInterfaceOrientation:correctOrientation duration:duration];
[contentViewController willAnimateRotationToInterfaceOrientation:correctOrientation duration:duration];
[tabBarViewController willAnimateRotationToInterfaceOrientation:correctOrientation duration:duration];
[stateBarViewController willAnimateRotationToInterfaceOrientation:correctOrientation duration:duration];
[super willAnimateRotationToInterfaceOrientation:currentOrientation duration:duration];
[contentViewController willAnimateRotationToInterfaceOrientation:currentOrientation duration:duration];
[tabBarViewController willAnimateRotationToInterfaceOrientation:currentOrientation duration:duration];
[stateBarViewController willAnimateRotationToInterfaceOrientation:currentOrientation duration:duration];
[self update:nil tabBar:nil fullscreen:nil];
}
@ -267,39 +256,36 @@
return controller;
}
- (UIInterfaceOrientation)getCorrectInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- (UIInterfaceOrientation)getCorrectInterfaceOrientation:(UIDeviceOrientation)deviceOrientation {
if(currentViewDescription != nil) {
NSString* rotationPreference = [[LinphoneManager instance].settingsStore objectForKey:@"rotation_preference"];
if([rotationPreference isEqualToString:@"auto"]) {
if(currentOrientation == UIDeviceOrientationUnknown) {
if(deviceOrientation == UIDeviceOrientationUnknown) {
return [UIApplication sharedApplication].statusBarOrientation;
}
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
if (UIDeviceOrientationIsPortrait(deviceOrientation)) {
if ([currentViewDescription portraitMode]) {
return interfaceOrientation;
return deviceOrientation;
} else {
return UIInterfaceOrientationLandscapeLeft;
}
}
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
if (UIDeviceOrientationIsLandscape(deviceOrientation)) {
if ([currentViewDescription landscapeMode]) {
return interfaceOrientation;
return deviceOrientation;
} else {
return UIInterfaceOrientationPortrait;
}
}
} else if([rotationPreference isEqualToString:@"portrait"]) {
if ([currentViewDescription landscapeMode]) {
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
if(currentOrientation == UIDeviceOrientationUnknown) {
if (UIDeviceOrientationIsPortrait(deviceOrientation)) {
if(deviceOrientation == UIDeviceOrientationUnknown) {
return [UIApplication sharedApplication].statusBarOrientation;
}
return interfaceOrientation;
return deviceOrientation;
} else {
if(UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
if(currentOrientation == UIDeviceOrientationUnknown) {
return [UIApplication sharedApplication].statusBarOrientation;
}
return [UIApplication sharedApplication].statusBarOrientation;
} else {
return UIInterfaceOrientationPortrait;
@ -310,16 +296,13 @@
}
} else if([rotationPreference isEqualToString:@"landscape"]) {
if ([currentViewDescription landscapeMode]) {
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
if(currentOrientation == UIDeviceOrientationUnknown) {
if (UIDeviceOrientationIsLandscape(deviceOrientation)) {
if(deviceOrientation == UIDeviceOrientationUnknown) {
return [UIApplication sharedApplication].statusBarOrientation;
}
return interfaceOrientation;
return deviceOrientation;
} else {
if(UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
if(currentOrientation == UIDeviceOrientationUnknown) {
return [UIApplication sharedApplication].statusBarOrientation;
}
return [UIApplication sharedApplication].statusBarOrientation;
} else {
return UIInterfaceOrientationLandscapeLeft;
@ -393,17 +376,11 @@
tabBarViewController = [self getCachedController:description.tabBar];
// Update rotation
UIDeviceOrientation correctOrientation = [self getCorrectInterfaceOrientation:currentOrientation];
if([UIApplication sharedApplication].statusBarOrientation != correctOrientation) {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIDeviceOrientationDidChangeNotification
object:nil];
[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)correctOrientation];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]];
if(currentOrientation != correctOrientation) {
[PhoneMainView forceOrientation:correctOrientation];
}
currentOrientation = correctOrientation;
[self updateInterfaceOrientation:correctOrientation];
} else {
oldViewDescription = (currentViewDescription != nil)? [currentViewDescription copy]: nil;

View file

@ -60,7 +60,6 @@
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="572758541"/>
<bool key="IBUIAutoresizesSubviews">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUITag">2</int>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
@ -73,7 +72,6 @@
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="572758541"/>
<bool key="IBUIAutoresizesSubviews">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUITag">3</int>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
@ -112,7 +110,6 @@
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="572758541"/>
<bool key="IBUIAutoresizesSubviews">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUITag">2</int>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
@ -125,7 +122,6 @@
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="572758541"/>
<bool key="IBUIAutoresizesSubviews">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<int key="IBUITag">3</int>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>

View file

@ -34,4 +34,4 @@
@end
void removeTableBackground(UIView* view);
void removeTableBackground(UIView* view);

View file

@ -21,6 +21,8 @@
#import "ColorSpaceUtilities.h"
#import "Utils.h"
#import <UIKit/UIView.h>
@implementation UIColor (LightAndDark)
- (UIColor *)lumColor:(float)mult {

View file

@ -37,6 +37,21 @@
<reference key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUIView" id="760939856">
<reference key="NSNextResponder" ref="1018893129"/>
<int key="NSvFlags">290</int>
<string key="NSFrame">{{0, 77}, {320, 2000}}</string>
<reference key="NSSuperview" ref="1018893129"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="318948703"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xNDkwMTk2MDc4IDAuMTY0NzA1ODgyNCAwLjE4MDM5MjE1NjkAA</bytes>
</object>
<int key="IBUITag">28</int>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="83510153">
<reference key="NSNextResponder" ref="1018893129"/>
<int key="NSvFlags">-2147483356</int>
@ -313,6 +328,7 @@
<string key="NSFrame">{{2, 2}, {17, 17}}</string>
<reference key="NSSuperview" ref="154031566"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
@ -343,7 +359,7 @@
<string key="NSFrameSize">{320, 77}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="318948703"/>
<reference key="NSNextKeyView" ref="760939856"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
@ -520,6 +536,7 @@
<reference ref="562688945"/>
<reference ref="698962606"/>
<reference ref="154031566"/>
<reference ref="760939856"/>
</array>
<reference key="parent" ref="0"/>
</object>
@ -604,6 +621,12 @@
<reference key="parent" ref="154031566"/>
<string key="objectName">chatNotificationImage</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">45</int>
<reference key="object" ref="760939856"/>
<reference key="parent" ref="1018893129"/>
<string key="objectName">background</string>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@ -620,6 +643,7 @@
<string key="38.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="39.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="45.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<real value="2" key="5.IBUIButtonInspectorSelectedStateConfigurationMetadataKey"/>
<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@ -635,7 +659,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">44</int>
<int key="maxID">45</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">

View file

@ -37,6 +37,21 @@
<reference key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUIView" id="103487099">
<reference key="NSNextResponder" ref="215340891"/>
<int key="NSvFlags">290</int>
<string key="NSFrame">{{0, 77}, {768, 2000}}</string>
<reference key="NSSuperview" ref="215340891"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="877138605"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xNDkwMTk2MDc4IDAuMTY0NzA1ODgyNCAwLjE4MDM5MjE1NjkAA</bytes>
</object>
<int key="IBUITag">28</int>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
<object class="IBUIView" id="783828575">
<reference key="NSNextResponder" ref="215340891"/>
<int key="NSvFlags">-2147483356</int>
@ -171,7 +186,7 @@
<string key="NSFrame">{{175, 0}, {175, 77}}</string>
<reference key="NSSuperview" ref="215340891"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="877138605"/>
<reference key="NSNextKeyView" ref="103487099"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<int key="IBUITag">3</int>
@ -364,6 +379,21 @@
<reference key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUIView" id="849328902">
<reference key="NSNextResponder" ref="774649127"/>
<int key="NSvFlags">290</int>
<string key="NSFrame">{{0, 86}, {1024, 2000}}</string>
<reference key="NSSuperview" ref="774649127"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="174827909"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xNDkwMTk2MDc4IDAuMTY0NzA1ODgyNCAwLjE4MDM5MjE1NjkAA</bytes>
</object>
<int key="IBUITag">28</int>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
<object class="IBUIView" id="91594118">
<reference key="NSNextResponder" ref="774649127"/>
<int key="NSvFlags">-2147483356</int>
@ -472,7 +502,7 @@
<string key="NSFrame">{{240, 0}, {240, 86}}</string>
<reference key="NSSuperview" ref="774649127"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="174827909"/>
<reference key="NSNextKeyView" ref="849328902"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<int key="IBUITag">3</int>
@ -828,6 +858,7 @@
<reference ref="1012118169"/>
<reference ref="582329659"/>
<reference ref="686020189"/>
<reference ref="103487099"/>
</array>
<reference key="parent" ref="0"/>
<string key="objectName">Portrait View</string>
@ -925,6 +956,7 @@
<reference ref="13787191"/>
<reference ref="129284976"/>
<reference ref="948217795"/>
<reference ref="849328902"/>
</array>
<reference key="parent" ref="0"/>
<string key="objectName">Landscape View</string>
@ -1010,6 +1042,18 @@
<reference key="parent" ref="774649127"/>
<string key="objectName">dialer</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">61</int>
<reference key="object" ref="103487099"/>
<reference key="parent" ref="215340891"/>
<string key="objectName">background</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">62</int>
<reference key="object" ref="849328902"/>
<reference key="parent" ref="774649127"/>
<string key="objectName">background</string>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@ -1049,6 +1093,8 @@
<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<real value="2" key="5.IBUIButtonInspectorSelectedStateConfigurationMetadataKey"/>
<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="61.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="62.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="7.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<real value="0.0" key="7.IBUIButtonInspectorSelectedStateConfigurationMetadataKey"/>
<string key="8.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@ -1060,7 +1106,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">60</int>
<int key="maxID">62</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -1088,7 +1134,7 @@
</object>
<object class="IBPartialClassDescription">
<string key="className">UIMainBar</string>
<string key="superclassName">UIViewController</string>
<string key="superclassName">TPMultiLayoutViewController</string>
<dictionary class="NSMutableDictionary" key="actions">
<string key="onChatClick:">id</string>
<string key="onContactsClick:">id</string>

View file

@ -59,6 +59,7 @@
- (UICompositeViewDescription *)firstView;
- (void)showTabBar:(BOOL)show;
- (void)fullScreen:(BOOL)enabled;
+ (void)forceOrientation:(UIInterfaceOrientation)orientation;
+ (PhoneMainView*) instance;

View file

@ -20,6 +20,7 @@
#import <QuartzCore/QuartzCore.h>
#import <AudioToolbox/AudioServices.h>
#import "LinphoneAppDelegate.h"
#import "PhoneMainView.h"
#import "Utils.h"
@ -30,6 +31,10 @@ static PhoneMainView* phoneMainViewInstance=nil;
@synthesize mainViewController;
@synthesize currentView;
// TO READ
// If a Controller set wantFullScreenLayout then DON'T set the autoresize!
// So DON'T set autoresize for PhoneMainView
#pragma mark - Lifecycle Functions
- (void)initPhoneMainView {
@ -164,19 +169,59 @@ static PhoneMainView* phoneMainViewInstance=nil;
}
}
/*
Will simulate a device rotation
*/
+ (void)forceOrientation:(UIInterfaceOrientation)orientation {
for(UIWindow *window in [[UIApplication sharedApplication] windows]) {
UIView *view = window;
UIViewController *controller = nil;
CGRect frame = [view frame];
if([window isKindOfClass:[UILinphoneWindow class]]) {
controller = window.rootViewController;
view = controller.view;
}
UIInterfaceOrientation oldOrientation = controller.interfaceOrientation;
[controller willRotateToInterfaceOrientation:orientation duration:0.3];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
switch (orientation) {
case UIInterfaceOrientationPortrait:
[view setTransform: CGAffineTransformMakeRotation(0)];
break;
case UIInterfaceOrientationPortraitUpsideDown:
[view setTransform: CGAffineTransformMakeRotation(M_PI)];
break;
case UIInterfaceOrientationLandscapeLeft:
[view setTransform: CGAffineTransformMakeRotation(-M_PI / 2)];
break;
case UIInterfaceOrientationLandscapeRight:
[view setTransform: CGAffineTransformMakeRotation(M_PI / 2)];
break;
default:
break;
}
if([window isKindOfClass:[UILinphoneWindow class]]) {
[view setFrame:frame];
}
[controller willAnimateRotationToInterfaceOrientation:orientation duration:0.3];
[UIView commitAnimations];
[controller didRotateFromInterfaceOrientation:oldOrientation];
}
[[UIApplication sharedApplication] setStatusBarOrientation:orientation animated:TRUE];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[mainViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self.view setFrame:[[UIScreen mainScreen] bounds]]; // Force resize to screen size
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
[mainViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
NSLog(@"%d", fromInterfaceOrientation);
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
[mainViewController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}

View file

@ -37,7 +37,7 @@
</object>
<object class="IBUIView" id="891400674">
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<int key="NSvFlags">301</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUIImageView" id="130212555">

View file

@ -1,17 +0,0 @@
//
// TPKeyboardAvoidingScrollView.h
//
// Created by Michael Tyson on 11/04/2011.
// Copyright 2011 A Tasty Pixel. All rights reserved.
//
@interface TPKeyboardAvoidingScrollView : UIScrollView {
UIEdgeInsets _priorInset;
BOOL _priorInsetSaved;
BOOL _keyboardVisible;
CGRect _keyboardRect;
CGSize _originalContentSize;
}
- (void)adjustOffsetToIdealIfNeeded;
@end

View file

@ -1,186 +0,0 @@
//
// TPKeyboardAvoidingScrollView.m
//
// Created by Michael Tyson on 11/04/2011.
// Copyright 2011 A Tasty Pixel. All rights reserved.
//
#import "TPKeyboardAvoidingScrollView.h"
#define _UIKeyboardFrameEndUserInfoKey (&UIKeyboardFrameEndUserInfoKey != NULL ? UIKeyboardFrameEndUserInfoKey : @"UIKeyboardBoundsUserInfoKey")
@interface TPKeyboardAvoidingScrollView ()
- (UIView*)findFirstResponderBeneathView:(UIView*)view;
- (UIEdgeInsets)contentInsetForKeyboard;
- (CGFloat)idealOffsetForView:(UIView *)view withSpace:(CGFloat)space;
- (CGRect)keyboardRect;
@end
@implementation TPKeyboardAvoidingScrollView
- (void)setup {
_priorInsetSaved = NO;
if ( CGSizeEqualToSize(self.contentSize, CGSizeZero) ) {
self.contentSize = self.bounds.size;
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
-(id)initWithFrame:(CGRect)frame {
if ( !(self = [super initWithFrame:frame]) ) return nil;
[self setup];
return self;
}
-(void)awakeFromNib {
[self setup];
}
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
#if !__has_feature(objc_arc)
[super dealloc];
#endif
}
-(void)setFrame:(CGRect)frame {
[super setFrame:frame];
CGSize contentSize = _originalContentSize;
contentSize.width = MAX(contentSize.width, self.frame.size.width);
contentSize.height = MAX(contentSize.height, self.frame.size.height);
[super setContentSize:contentSize];
if ( _keyboardVisible ) {
self.contentInset = [self contentInsetForKeyboard];
}
}
-(void)setContentSize:(CGSize)contentSize {
_originalContentSize = contentSize;
contentSize.width = MAX(contentSize.width, self.frame.size.width);
contentSize.height = MAX(contentSize.height, self.frame.size.height);
[super setContentSize:contentSize];
if ( _keyboardVisible ) {
self.contentInset = [self contentInsetForKeyboard];
}
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[self findFirstResponderBeneathView:self] resignFirstResponder];
[super touchesEnded:touches withEvent:event];
}
- (void)keyboardWillShow:(NSNotification*)notification {
_keyboardRect = [[[notification userInfo] objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue];
_keyboardVisible = YES;
UIView *firstResponder = [self findFirstResponderBeneathView:self];
if ( !firstResponder ) {
// No child view is the first responder - nothing to do here
return;
}
if (!_priorInsetSaved) {
_priorInset = self.contentInset;
_priorInsetSaved = YES;
}
// Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
self.contentInset = [self contentInsetForKeyboard];
[self setContentOffset:CGPointMake(self.contentOffset.x,
[self idealOffsetForView:firstResponder withSpace:[self keyboardRect].origin.y - self.bounds.origin.y])
animated:YES];
[self setScrollIndicatorInsets:self.contentInset];
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification*)notification {
_keyboardRect = CGRectZero;
_keyboardVisible = NO;
// Restore dimensions to prior size
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
self.contentInset = _priorInset;
[self setScrollIndicatorInsets:self.contentInset];
_priorInsetSaved = NO;
[UIView commitAnimations];
}
- (UIView*)findFirstResponderBeneathView:(UIView*)view {
// Search recursively for first responder
for ( UIView *childView in view.subviews ) {
if ( [childView respondsToSelector:@selector(isFirstResponder)] && [childView isFirstResponder] ) return childView;
UIView *result = [self findFirstResponderBeneathView:childView];
if ( result ) return result;
}
return nil;
}
- (UIEdgeInsets)contentInsetForKeyboard {
UIEdgeInsets newInset = self.contentInset;
CGRect keyboardRect = [self keyboardRect];
newInset.bottom = keyboardRect.size.height - ((keyboardRect.origin.y+keyboardRect.size.height) - (self.bounds.origin.y+self.bounds.size.height));
return newInset;
}
-(CGFloat)idealOffsetForView:(UIView *)view withSpace:(CGFloat)space {
// Convert the rect to get the view's distance from the top of the scrollView.
CGRect rect = [view convertRect:view.bounds toView:self];
// Set starting offset to that point
CGFloat offset = rect.origin.y;
if ( self.contentSize.height - offset < space ) {
// Scroll to the bottom
offset = self.contentSize.height - space;
} else {
if ( view.bounds.size.height < space ) {
// Center vertically if there's room
offset -= floor((space-view.bounds.size.height)/2.0);
}
if ( offset + space > self.contentSize.height ) {
// Clamp to content size
offset = self.contentSize.height - space;
}
}
if (offset < 0) offset = 0;
return offset;
}
-(void)adjustOffsetToIdealIfNeeded {
// Only do this if the keyboard is already visible
if ( !_keyboardVisible ) return;
CGFloat visibleSpace = self.bounds.size.height - self.contentInset.top - self.contentInset.bottom;
CGPoint idealOffset = CGPointMake(0, [self idealOffsetForView:[self findFirstResponderBeneathView:self] withSpace:visibleSpace]);
[self setContentOffset:idealOffset animated:YES];
}
- (CGRect)keyboardRect {
CGRect keyboardRect = [self convertRect:_keyboardRect fromView:nil];
if ( keyboardRect.origin.y == 0 ) {
CGRect screenBounds = [self convertRect:[UIScreen mainScreen].bounds fromView:nil];
keyboardRect.origin = CGPointMake(0, screenBounds.size.height - keyboardRect.size.height);
}
return keyboardRect;
}
@end

View file

@ -1,16 +0,0 @@
//
// TPKeyboardAvoidingTableView.h
//
// Created by Michael Tyson on 11/04/2011.
// Copyright 2011 A Tasty Pixel. All rights reserved.
//
@interface TPKeyboardAvoidingTableView : UITableView {
UIEdgeInsets _priorInset;
BOOL _priorInsetSaved;
BOOL _keyboardVisible;
CGRect _keyboardRect;
}
- (void)adjustOffsetToIdealIfNeeded;
@end

View file

@ -1,173 +0,0 @@
//
// TPKeyboardAvoidingTableView.m
//
// Created by Michael Tyson on 11/04/2011.
// Copyright 2011 A Tasty Pixel. All rights reserved.
//
#import "TPKeyboardAvoidingTableView.h"
#define _UIKeyboardFrameEndUserInfoKey (&UIKeyboardFrameEndUserInfoKey != NULL ? UIKeyboardFrameEndUserInfoKey : @"UIKeyboardBoundsUserInfoKey")
@interface TPKeyboardAvoidingTableView ()
- (UIView*)findFirstResponderBeneathView:(UIView*)view;
- (UIEdgeInsets)contentInsetForKeyboard;
- (CGFloat)idealOffsetForView:(UIView *)view withSpace:(CGFloat)space;
- (CGRect)keyboardRect;
@end
@implementation TPKeyboardAvoidingTableView
- (void)setup {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
-(id)initWithFrame:(CGRect)frame {
if ( !(self = [super initWithFrame:frame]) ) return nil;
[self setup];
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder {
if ( !(self = [super initWithCoder:aDecoder]) ) return nil;
[self setup];
return self;
}
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
#if !__has_feature(objc_arc)
[super dealloc];
#endif
}
-(void)setFrame:(CGRect)frame {
[super setFrame:frame];
if ( _keyboardVisible ) {
self.contentInset = [self contentInsetForKeyboard];
}
}
-(void)setContentSize:(CGSize)contentSize {
[super setContentSize:contentSize];
if ( _keyboardVisible ) {
self.contentInset = [self contentInsetForKeyboard];
}
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[self findFirstResponderBeneathView:self] resignFirstResponder];
[super touchesEnded:touches withEvent:event];
}
- (void)keyboardWillShow:(NSNotification*)notification {
_keyboardRect = [[[notification userInfo] objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue];
_keyboardVisible = YES;
UIView *firstResponder = [self findFirstResponderBeneathView:self];
if ( !firstResponder ) {
// No child view is the first responder - nothing to do here
return;
}
if (!_priorInsetSaved) {
_priorInset = self.contentInset;
_priorInsetSaved = YES;
}
// Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
self.contentInset = [self contentInsetForKeyboard];
[self setContentOffset:CGPointMake(self.contentOffset.x,
[self idealOffsetForView:firstResponder withSpace:[self keyboardRect].origin.y - self.bounds.origin.y])
animated:YES];
[self setScrollIndicatorInsets:self.contentInset];
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification*)notification {
_keyboardRect = CGRectZero;
_keyboardVisible = NO;
// Restore dimensions to prior size
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
self.contentInset = _priorInset;
[self setScrollIndicatorInsets:self.contentInset];
_priorInsetSaved = NO;
[UIView commitAnimations];
}
- (UIView*)findFirstResponderBeneathView:(UIView*)view {
// Search recursively for first responder
for ( UIView *childView in view.subviews ) {
if ( [childView respondsToSelector:@selector(isFirstResponder)] && [childView isFirstResponder] ) return childView;
UIView *result = [self findFirstResponderBeneathView:childView];
if ( result ) return result;
}
return nil;
}
- (UIEdgeInsets)contentInsetForKeyboard {
UIEdgeInsets newInset = self.contentInset;
CGRect keyboardRect = [self keyboardRect];
newInset.bottom = keyboardRect.size.height - ((keyboardRect.origin.y+keyboardRect.size.height) - (self.bounds.origin.y+self.bounds.size.height));
return newInset;
}
-(CGFloat)idealOffsetForView:(UIView *)view withSpace:(CGFloat)space {
// Convert the rect to get the view's distance from the top of the scrollView.
CGRect rect = [view convertRect:view.bounds toView:self];
// Set starting offset to that point
CGFloat offset = rect.origin.y;
if ( self.contentSize.height - offset < space ) {
// Scroll to the bottom
offset = self.contentSize.height - space;
} else {
if ( view.bounds.size.height < space ) {
// Center vertically if there's room
offset -= floor((space-view.bounds.size.height)/2.0);
}
if ( offset + space > self.contentSize.height ) {
// Clamp to content size
offset = self.contentSize.height - space;
}
}
if (offset < 0) offset = 0;
return offset;
}
-(void)adjustOffsetToIdealIfNeeded {
// Only do this if the keyboard is already visible
if ( !_keyboardVisible ) return;
CGFloat visibleSpace = self.bounds.size.height - self.contentInset.top - self.contentInset.bottom;
CGPoint idealOffset = CGPointMake(0, [self idealOffsetForView:[self findFirstResponderBeneathView:self] withSpace:visibleSpace]);
[self setContentOffset:idealOffset animated:YES];
}
- (CGRect)keyboardRect {
CGRect keyboardRect = [self convertRect:_keyboardRect fromView:nil];
if ( keyboardRect.origin.y == 0 ) {
CGRect screenBounds = [self convertRect:[UIScreen mainScreen].bounds fromView:nil];
keyboardRect.origin = CGPointMake(0, screenBounds.size.height - keyboardRect.size.height);
}
return keyboardRect;
}
@end

View file

@ -1116,10 +1116,6 @@
D3F83F8F15822ABE00336684 /* PhoneMainView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F83F8D15822ABD00336684 /* PhoneMainView.m */; };
D3F83F9215824D3600336684 /* LinphoneApp.xib in Resources */ = {isa = PBXBuildFile; fileRef = D3F83F9115824D3500336684 /* LinphoneApp.xib */; };
D3F9A9DB15AEEB940045320F /* history_notification.png in Resources */ = {isa = PBXBuildFile; fileRef = D3F9A9DA15AEEB940045320F /* history_notification.png */; };
D3F9A9E215AF100D0045320F /* TPKeyboardAvoidingScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F9A9DF15AF100D0045320F /* TPKeyboardAvoidingScrollView.m */; };
D3F9A9E315AF100D0045320F /* TPKeyboardAvoidingScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F9A9DF15AF100D0045320F /* TPKeyboardAvoidingScrollView.m */; };
D3F9A9E415AF100D0045320F /* TPKeyboardAvoidingTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F9A9E115AF100D0045320F /* TPKeyboardAvoidingTableView.m */; };
D3F9A9E515AF100D0045320F /* TPKeyboardAvoidingTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F9A9E115AF100D0045320F /* TPKeyboardAvoidingTableView.m */; };
D3F9A9EE15AF277E0045320F /* UACellBackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F9A9ED15AF277D0045320F /* UACellBackgroundView.m */; };
D3F9A9EF15AF277E0045320F /* UACellBackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = D3F9A9ED15AF277D0045320F /* UACellBackgroundView.m */; };
F476004B147AAF2800FFF19B /* liblinphone.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2211DB911475562600DEE054 /* liblinphone.a */; };
@ -2003,10 +1999,6 @@
D3F83F8D15822ABD00336684 /* PhoneMainView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PhoneMainView.m; sourceTree = "<group>"; };
D3F83F9115824D3500336684 /* LinphoneApp.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LinphoneApp.xib; sourceTree = "<group>"; };
D3F9A9DA15AEEB940045320F /* history_notification.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = history_notification.png; path = Resources/history_notification.png; sourceTree = "<group>"; };
D3F9A9DE15AF100D0045320F /* TPKeyboardAvoidingScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TPKeyboardAvoidingScrollView.h; path = Utils/TPKeyboardAvoiding/TPKeyboardAvoidingScrollView.h; sourceTree = "<group>"; };
D3F9A9DF15AF100D0045320F /* TPKeyboardAvoidingScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TPKeyboardAvoidingScrollView.m; path = Utils/TPKeyboardAvoiding/TPKeyboardAvoidingScrollView.m; sourceTree = "<group>"; };
D3F9A9E015AF100D0045320F /* TPKeyboardAvoidingTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TPKeyboardAvoidingTableView.h; path = Utils/TPKeyboardAvoiding/TPKeyboardAvoidingTableView.h; sourceTree = "<group>"; };
D3F9A9E115AF100D0045320F /* TPKeyboardAvoidingTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TPKeyboardAvoidingTableView.m; path = Utils/TPKeyboardAvoiding/TPKeyboardAvoidingTableView.m; sourceTree = "<group>"; };
D3F9A9EC15AF277D0045320F /* UACellBackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UACellBackgroundView.h; path = Utils/UACellBackgroundView/UACellBackgroundView.h; sourceTree = "<group>"; };
D3F9A9ED15AF277D0045320F /* UACellBackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UACellBackgroundView.m; path = Utils/UACellBackgroundView/UACellBackgroundView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -3050,7 +3042,6 @@
D3B90E1115C2CB5700F64F8C /* NinePatch.xcodeproj */,
D326483615887D5200930C67 /* OrderedDictionary.h */,
D326483715887D5200930C67 /* OrderedDictionary.m */,
D3F9A9DD15AF0FFE0045320F /* TPKeyboardAvoiding */,
D3F7997E15BD31EC0018C273 /* TPMultiLayoutViewController */,
D3F9A9EB15AF27620045320F /* UACellBackgroundView */,
C9B3A6FD15B485DB006F52EE /* Utils.h */,
@ -3181,17 +3172,6 @@
name = TPMultiLayoutViewController;
sourceTree = "<group>";
};
D3F9A9DD15AF0FFE0045320F /* TPKeyboardAvoiding */ = {
isa = PBXGroup;
children = (
D3F9A9DE15AF100D0045320F /* TPKeyboardAvoidingScrollView.h */,
D3F9A9DF15AF100D0045320F /* TPKeyboardAvoidingScrollView.m */,
D3F9A9E015AF100D0045320F /* TPKeyboardAvoidingTableView.h */,
D3F9A9E115AF100D0045320F /* TPKeyboardAvoidingTableView.m */,
);
name = TPKeyboardAvoiding;
sourceTree = "<group>";
};
D3F9A9EB15AF27620045320F /* UACellBackgroundView */ = {
isa = PBXGroup;
children = (
@ -4230,8 +4210,6 @@
D378906515AC373B00BD776C /* ContactDetailsLabelViewController.m in Sources */,
D3E8F68615ADE05B0065A226 /* UIContactDetailsFooter.m in Sources */,
C90FAA7915AF54E6002091CB /* HistoryDetailsViewController.m in Sources */,
D3F9A9E215AF100D0045320F /* TPKeyboardAvoidingScrollView.m in Sources */,
D3F9A9E415AF100D0045320F /* TPKeyboardAvoidingTableView.m in Sources */,
D3F9A9EE15AF277E0045320F /* UACellBackgroundView.m in Sources */,
D35860D615B549B500513429 /* Utils.m in Sources */,
D3F7998115BD32370018C273 /* TPMultiLayoutViewController.m in Sources */,
@ -4323,8 +4301,6 @@
D378906615AC373B00BD776C /* ContactDetailsLabelViewController.m in Sources */,
D3E8F68715ADE05B0065A226 /* UIContactDetailsFooter.m in Sources */,
C90FAA7A15AF54E6002091CB /* HistoryDetailsViewController.m in Sources */,
D3F9A9E315AF100D0045320F /* TPKeyboardAvoidingScrollView.m in Sources */,
D3F9A9E515AF100D0045320F /* TPKeyboardAvoidingTableView.m in Sources */,
D3F9A9EF15AF277E0045320F /* UACellBackgroundView.m in Sources */,
D35860D715B549B500513429 /* Utils.m in Sources */,
D3F7998215BD32370018C273 /* TPMultiLayoutViewController.m in Sources */,