iOS 6.1的行为与willTransitionToState不同 [英] iOS 6.1 is acting differently with willTransitionToState

查看:194
本文介绍了iOS 6.1的行为与willTransitionToState不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将子类化我的 UITableCell ,以移动减号图像和删除图像在EditMode到相反的方向。它的工作伟大到目前为止,但在iOS 6当我使用reloadData在我的tableView减图像跳转到单元格的左侧,而不是停留在右边。我不知道什么改变在iOS 6中触发的行为。



我不知道这是什么原因导致的问题,但我已经记录所有的起源在iOS 5和iOS 6,唯一的区别是:



iOS 5.0:
日志5 - 状态1和3: 560.000000 ,0.000000,41.000000,40.000000

iOS 6.1:
日志5 - 状态1和3: 808.000000 ,0.000000,41.000000,40.000000



以下是代码:



.h:

  #import< UIKit / UIKit.h> 

#define UITableViewCellEditControlOffset 280
#define UITableViewCellDeleteConfirmationControlOffset 250
#define UITableViewCellAnimationOffset 20
#define UITableViewCellAnimationDuration 0.0
#define BigCellHeight 40
#define SmallCellHeight 40

typedef枚举{
Name = -1,
添加= -2,
价格= -3,
BackgroundImage = -4,
Line = -5,
Edit = -6,
Plate = -7,
Sign = -8
} CellData;

@interface RTLUITableViewCelliPhone:UITableViewCell {
UITableViewCellStateMask state;
BOOL editHiddenEarlier,priceHiddenEarlier;
}

@property(nonatomic,assign)BOOL inEditingMode;
@property(nonatomic,assign)BOOL可编辑,可移动;

.m:


$ b b

  #importRTLUITableViewCelliPhone.h

@implementation RTLUITableViewCelliPhone

@synthesize可编辑,可移动,inEditingMode;

- (void)layoutSubviews {
[super layoutSubviews];
self.contentView.frame = CGRectMake(0,0,320,BigCellHeight);
}

- (void)willTransitionToState:(UITableViewCellStateMask)aState {
[super willTransitionToState:aState];
state = aState;
if(state == 0){
for(UIView * subview in self.subviews){
if([NSStringFromClass([subview class])isEqualToString:@UITableViewCellEditControl]){
UIView * noEntranceView = [subview.subviews objectAtIndex:0];
noEntranceView.alpha = 0;
}
if([NSStringFromClass([subview class])isEqualToString:@UITableViewCellDeleteConfirmationControl]){
UIView * deleteView = [subview.subviews objectAtIndex:0];
deleteView.alpha = 0;
}
}
}
if(state == 1 || state == 3){
for(UIView * subview in self.subviews){
if([NSStringFromClass([subview class])isEqualToString:@UITableViewCellEditControl]){
UIView * noEntranceView = [subview.subviews objectAtIndex:0];
noEntranceView.alpha = 0;
subview.frame = CGRectMake(subview.frame.origin.x + UITableViewCellEditControlOffset,subview.frame.origin.y,subview.frame.size.width,subview.frame.size.height);
NSLog(@Log 1 - State 1 And 3:%f,%f,%f,%f,subview.frame.origin.x + UITableViewCellEditControlOffset,subview.frame.origin.y,subview.frame .size.width,subview.frame.size.height);
}
if([NSStringFromClass([subview class])isEqualToString:@UITableViewCellDeleteConfirmationControl]){
UIView * deleteView = [subview.subviews objectAtIndex:0];
deleteView.alpha = 0;
subview.frame = CGRectMake(subview.frame.origin.x-UITableViewCellDeleteConfirmationControlOffset,subview.frame.origin.y,subview.frame.size.width,subview.frame.size.height);
NSLog(@Log 2 - State 1 And 3:%f,%f,%f,%f,subview.frame.origin.x-UITableViewCellDeleteConfirmationControlOffset,subview.frame.origin.y,subview.frame .size.width,subview.frame.size.height);
}
}
}
if([self inEditingMode]){
if(state == 3){
editHiddenEarlier = [self.contentView viewWithTag :Edit] .hidden;
priceHiddenEarlier = [self.contentView viewWithTag:Price] .hidden;
[self.contentView viewWithTag:Sign] .hidden = [self.contentView viewWithTag:Edit] .hidden = [self.contentView viewWithTag:Price] .hidden = YES;
}
if(state == 1){
[self.contentView viewWithTag:Edit] .hidden =!self.editable || editHiddenEarlier;
[self.contentView viewWithTag:Sign] .hidden = [self.contentView viewWithTag:Price] .hidden =![self.contentView viewWithTag:Edit] .hidden;
}
}
}

- (void)didTransitionToState:(UITableViewCellStateMask)aState {
[super didTransitionToState:aState];
state = aState;
if(state == 0){//结束编辑

for(UIView * subview in self.subviews){
if([NSStringFromClass([subview class])isEqualToString :@UITableViewCellEditControl]){
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:UITableViewCellAnimationDuration];
UIView * noEntranceView = [subview.subviews objectAtIndex:0];
noEntranceView.alpha = 1;
noEntranceView.frame = CGRectMake(noEntranceView.frame.origin.x + UITableViewCellAnimationOffset,noEntranceView.frame.origin.y,noEntranceView.frame.size.width,
noEntranceView.frame.size.height);
[UIView commitAnimations];
NSLog(@Log 3 - State 0:%f,%f,%f,%f,noEntranceView.frame.origin.x + UITableViewCellAnimationOffset,noEntranceView.frame.origin.y,noEntranceView.frame.size .width,
noEntranceView.frame.size.height);

}

if([NSStringFromClass([subview class])isEqualToString:@UITableViewCellDeleteConfirmationControl]){
UIView * deleteView = [subview.subviews objectAtIndex: 0];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:UITableViewCellAnimationDuration];
deleteView.alpha = 1;
deleteView.frame = CGRectMake(deleteView.frame.origin.x-UITableViewCellAnimationOffset,deleteView.frame.origin.y,deleteView.frame.size.width,deleteView.frame.size.height);
[UIView commitAnimations];
NSLog(@Log 4 - State 0:%f,%f,%f,%f,deleteView.frame.origin.x-UITableViewCellAnimationOffset,deleteView.frame.origin.y,deleteView.frame.size .width,deleteView.frame.size.height);
}
}
}
if(state == 1 || state == 3){
for(UIView * subview in self.subviews){
if([NSStringFromClass([subview class])isEqualToString:@UITableViewCellEditControl]){
subview.frame = CGRectMake(560,subview.frame.origin.y,subview.frame.size.width,subview .frame.size.height);
NSLog(@Log 5 - State 1 And 3:%f,%f,%f,%f,subview.frame.origin.x + UITableViewCellEditControlOffset,subview.frame.origin.y,subview.frame .size.width,subview.frame.size.height);

UIView * noEntranceView = [subview.subviews objectAtIndex:0];
noEntranceView.frame = CGRectMake(noEntranceView.frame.origin.x + UITableViewCellAnimationOffset,noEntranceView.frame.origin.y,noEntranceView.frame.size.width,
noEntranceView.frame.size.height);
NSLog(@Log 6 - State 1 And 3:%f,%f,%f,%f,noEntranceView.frame.origin.x + UITableViewCellAnimationOffset,noEntranceView.frame.origin.y,noEntranceView.frame .size.width,
noEntranceView.frame.size.height);


[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:UITableViewCellAnimationDuration];
noEntranceView.alpha = 1;
noEntranceView.frame = CGRectMake(noEntranceView.frame.origin.x-UITableViewCellAnimationOffset,noEntranceView.frame.origin.y,noEntranceView.frame.size.width,noEntranceView.frame.size.height);

[UIView commitAnimations];
NSLog(@Log 7 - State 1 And 3:%f,%f,%f,%f,noEntranceView.frame.origin.x-UITableViewCellAnimationOffset,noEntranceView.frame.origin.y,noEntranceView.frame .size.width,noEntranceView.frame.size.height);
}
if([NSStringFromClass([subview class])isEqualToString:@UITableViewCellDeleteConfirmationControl]){
subview.frame = CGRectMake(subview.frame.origin.x-UITableViewCellDeleteConfirmationControlOffset,subview。 frame.origin.y,subview.frame.size.width,subview.frame.size.height);
NSLog(@Log 8 - State 1 And 3:%f,%f,%f,%f,subview.frame.origin.x-UITableViewCellDeleteConfirmationControlOffset,subview.frame.origin.y,subview.frame .size.width,subview.frame.size.height);
UIView * deleteView = [subview.subviews objectAtIndex:0];
deleteView.frame = CGRectMake(deleteView.frame.origin.x-UITableViewCellAnimationOffset,deleteView.frame.origin.y,deleteView.frame.size.width,deleteView.frame.size.height);
NSLog(@Log 9 - State 1 And 3:%f,%f,%f,%f,deleteView.frame.origin.x-UITableViewCellAnimationOffset,deleteView.frame.origin.y,deleteView.frame .size.width,deleteView.frame.size.height);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:UITableViewCellAnimationDuration];
deleteView.alpha = 1;
deleteView.frame = CGRectMake(deleteView.frame.origin.x + UITableViewCellAnimationOffset,deleteView.frame.origin.y,deleteView.frame.size.width,deleteView.frame.size.height);
[UIView commitAnimations];
NSLog(@Log 10 - State 1 And 3:%f,%f,%f,%f,deleteView.frame.origin.x + UITableViewCellAnimationOffset,deleteView.frame.origin.y,deleteView.frame .size.width,deleteView.frame.size.height);
}
}
}
}

@end


解决方案

如果在xib上启用了自动布局,可能是问题的原因。此答案可能提供一些见解 contentView不缩进iOS 6 UITableViewCell原型单元


I'm subclassing my UITableCell in order move the Minus image and the Delete image in EditMode to the oposite direction. It worked great so far but in iOS 6 when I use reloadData on my tableView the minus image jumps to the left side of the cell instead of staying on the right. I have no idea what changed in iOS 6 to trigger that behavior.

I don't know if that's what is causing the issue but I've logged all the origins in iOS 5 and iOS 6 and the only difference was:

iOS 5.0: Log 5 - State 1 And 3: 560.000000 , 0.000000 , 41.000000 , 40.000000

iOS 6.1: Log 5 - State 1 And 3: 808.000000 , 0.000000 , 41.000000 , 40.000000

Here's the code:

.h:

#import <UIKit/UIKit.h>

#define UITableViewCellEditControlOffset 280
#define UITableViewCellDeleteConfirmationControlOffset 250
#define UITableViewCellAnimationOffset 20
#define UITableViewCellAnimationDuration 0.0
#define BigCellHeight 40
#define SmallCellHeight 40

typedef enum{
    Name = -1,
    Additions = -2,
    Price = -3,
    BackgroundImage = -4,
    Line = -5,
    Edit = -6, 
    Plate = -7,
    Sign = -8
}CellData;

@interface RTLUITableViewCelliPhone : UITableViewCell {
    UITableViewCellStateMask state;
    BOOL editHiddenEarlier, priceHiddenEarlier;
}

@property (nonatomic, assign) BOOL inEditingMode;
@property (nonatomic, assign) BOOL editable, removable;

.m:

#import "RTLUITableViewCelliPhone.h"

@implementation RTLUITableViewCelliPhone

@synthesize editable, removable, inEditingMode;

- (void)layoutSubviews{
    [super layoutSubviews];
    self.contentView.frame = CGRectMake(0, 0, 320, BigCellHeight);
}

- (void)willTransitionToState:(UITableViewCellStateMask)aState{
    [super willTransitionToState:aState];
    state = aState;
    if (state==0) {
        for (UIView *subview in self.subviews){
            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]){
                UIView *noEntranceView = [subview.subviews objectAtIndex:0];                
                noEntranceView.alpha = 0;
            }
            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]){                
                UIView *deleteView = [subview.subviews objectAtIndex:0];
                deleteView.alpha = 0;
            }
        }
    }
    if (state==1 || state==3){
        for (UIView *subview in self.subviews){
            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]){
                UIView *noEntranceView = [subview.subviews objectAtIndex:0];
                noEntranceView.alpha = 0;
                subview.frame = CGRectMake(subview.frame.origin.x+UITableViewCellEditControlOffset, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
                NSLog(@"Log 1 - State 1 And 3: %f , %f , %f , %f ",subview.frame.origin.x+UITableViewCellEditControlOffset, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
            }
            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]){
                UIView *deleteView = [subview.subviews objectAtIndex:0];
                deleteView.alpha = 0;
                subview.frame = CGRectMake(subview.frame.origin.x-UITableViewCellDeleteConfirmationControlOffset, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
                NSLog(@"Log 2 - State 1 And 3: %f , %f , %f , %f ",subview.frame.origin.x-UITableViewCellDeleteConfirmationControlOffset, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
            }
        }
    }
    if ([self inEditingMode]) {
        if (state==3) {
            editHiddenEarlier = [self.contentView viewWithTag:Edit].hidden;
            priceHiddenEarlier = [self.contentView viewWithTag:Price].hidden;
            [self.contentView viewWithTag:Sign].hidden = [self.contentView viewWithTag:Edit].hidden = [self.contentView viewWithTag:Price].hidden = YES;
        }
        if (state==1) {
            [self.contentView viewWithTag:Edit].hidden = !self.editable || editHiddenEarlier;
            [self.contentView viewWithTag:Sign].hidden = [self.contentView viewWithTag:Price].hidden = ![self.contentView viewWithTag:Edit].hidden;
        }
    }
}

- (void)didTransitionToState:(UITableViewCellStateMask)aState{
    [super didTransitionToState:aState];
    state = aState;
    if (state==0) { // End editing

        for (UIView *subview in self.subviews){
            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]){
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:UITableViewCellAnimationDuration];
                UIView *noEntranceView = [subview.subviews objectAtIndex:0];                
                noEntranceView.alpha = 1;
                noEntranceView.frame = CGRectMake(noEntranceView.frame.origin.x+UITableViewCellAnimationOffset, noEntranceView.frame.origin.y, noEntranceView.frame.size.width, 
                                                  noEntranceView.frame.size.height);
                [UIView commitAnimations];
                NSLog(@"Log 3 - State 0: %f , %f , %f , %f ",noEntranceView.frame.origin.x+UITableViewCellAnimationOffset, noEntranceView.frame.origin.y, noEntranceView.frame.size.width,
                      noEntranceView.frame.size.height);

            }

            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]){                
                UIView *deleteView = [subview.subviews objectAtIndex:0];

                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:UITableViewCellAnimationDuration];
                deleteView.alpha = 1;
                deleteView.frame = CGRectMake(deleteView.frame.origin.x-UITableViewCellAnimationOffset, deleteView.frame.origin.y, deleteView.frame.size.width, deleteView.frame.size.height);
                [UIView commitAnimations];
                NSLog(@"Log 4 - State 0: %f , %f , %f , %f ",deleteView.frame.origin.x-UITableViewCellAnimationOffset, deleteView.frame.origin.y, deleteView.frame.size.width, deleteView.frame.size.height);
            }
        }
    }
    if (state==1 || state==3){
        for (UIView *subview in self.subviews){
            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]){
                subview.frame = CGRectMake(560, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
                NSLog(@"Log 5 - State 1 And 3: %f , %f , %f , %f ",subview.frame.origin.x+UITableViewCellEditControlOffset, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);

                UIView *noEntranceView = [subview.subviews objectAtIndex:0];
                noEntranceView.frame = CGRectMake(noEntranceView.frame.origin.x+UITableViewCellAnimationOffset, noEntranceView.frame.origin.y, noEntranceView.frame.size.width,
                                                  noEntranceView.frame.size.height);
                NSLog(@"Log 6 - State 1 And 3: %f , %f , %f , %f ",noEntranceView.frame.origin.x+UITableViewCellAnimationOffset, noEntranceView.frame.origin.y, noEntranceView.frame.size.width,
                      noEntranceView.frame.size.height);


                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:UITableViewCellAnimationDuration];
                noEntranceView.alpha = 1;
                noEntranceView.frame = CGRectMake(noEntranceView.frame.origin.x-UITableViewCellAnimationOffset, noEntranceView.frame.origin.y, noEntranceView.frame.size.width, noEntranceView.frame.size.height);

                [UIView commitAnimations];
                NSLog(@"Log 7 - State 1 And 3: %f , %f , %f , %f ",noEntranceView.frame.origin.x-UITableViewCellAnimationOffset, noEntranceView.frame.origin.y, noEntranceView.frame.size.width, noEntranceView.frame.size.height);
            }
            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]){
                subview.frame = CGRectMake(subview.frame.origin.x-UITableViewCellDeleteConfirmationControlOffset, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
                NSLog(@"Log 8 - State 1 And 3: %f , %f , %f , %f ",subview.frame.origin.x-UITableViewCellDeleteConfirmationControlOffset, subview.frame.origin.y, subview.frame.size.width, subview.frame.size.height);
                UIView *deleteView = [subview.subviews objectAtIndex:0];
                deleteView.frame = CGRectMake(deleteView.frame.origin.x-UITableViewCellAnimationOffset, deleteView.frame.origin.y, deleteView.frame.size.width, deleteView.frame.size.height);
                NSLog(@"Log 9 - State 1 And 3: %f , %f , %f , %f ",deleteView.frame.origin.x-UITableViewCellAnimationOffset, deleteView.frame.origin.y, deleteView.frame.size.width, deleteView.frame.size.height);
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:UITableViewCellAnimationDuration];
                deleteView.alpha = 1;
                deleteView.frame = CGRectMake(deleteView.frame.origin.x+UITableViewCellAnimationOffset, deleteView.frame.origin.y, deleteView.frame.size.width, deleteView.frame.size.height);
                [UIView commitAnimations];
                NSLog(@"Log 10 - State 1 And 3: %f , %f , %f , %f ",deleteView.frame.origin.x+UITableViewCellAnimationOffset, deleteView.frame.origin.y, deleteView.frame.size.width, deleteView.frame.size.height);
            }
        }
    }
}

@end

解决方案

If auto-layout is enabled on the xib it could be the cause of the issue. This answer may provide some insight contentView not indenting in iOS 6 UITableViewCell prototype cell

这篇关于iOS 6.1的行为与willTransitionToState不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆