解決策を指摘してくれたA-Liveに感謝します。問題を解決するには、このリンクとこのリンクの両方に基づくソリューションを使用する必要がありました。まず、UITableViewCellのサブクラスを作成する必要がありました。ここで、setEditingを再実装し、observeValueForKeyPath関数を追加しました。
最初のステップで、observeValueForKeyPathはcontentViewのインデントを禁止し、2番目にsetEditingがtextLabelのアニメーションを処理します
これが私のコードです:
#import "UI_CategoryTableViewCell.h"
@implementation UI_CategoryTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self.contentView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionOld context:nil];
}
return self;
}
- (void)dealloc
{
[self.contentView removeObserver:self forKeyPath:@"frame"];
[super dealloc];
}
- (void)layoutSubviews
{
[super layoutSubviews];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.0f];
for (UIView *subview in self.subviews) {
//NSLog(@"%@", NSStringFromClass([subview class]));
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 416;
newFrame.origin.y = -26;
subview.frame = newFrame;
}
else if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 5;
newFrame.origin.y = -31;
subview.frame = newFrame;
}
}
[UIView commitAnimations];
if ([super showingDeleteConfirmation] || [super isEditing]) {
self.textLabel.frame = CGRectMake(38,-30, self.textLabel.frame.size.width, self.textLabel.frame.size.height);
}
else{
self.textLabel.frame = CGRectMake(10,-30,self.textLabel.frame.size.width, self.textLabel.frame.size.height);
}
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
//NSLog(@"observed value for kp %@ changed: %@",keyPath,change);
if ( [keyPath isEqual:@"frame"] && object == self.contentView )
{
CGRect newFrame = self.contentView.frame;
CGRect oldFrame = [[change objectForKey:NSKeyValueChangeOldKey] CGRectValue];
//NSLog(@"frame old: %@ new: %@",NSStringFromCGRect(oldFrame),NSStringFromCGRect(newFrame));
if ( newFrame.origin.x != 0 )
self.contentView.frame = oldFrame;
}
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
[super setEditing:editing animated:animate];
if(editing) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
self.textLabel.frame = CGRectMake(38,-30, self.textLabel.frame.size.width, self.textLabel.frame.size.height);
[UIView commitAnimations];
} else {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
self.textLabel.frame = CGRectMake(10,-30, self.textLabel.frame.size.width, self.textLabel.frame.size.height);
[UIView commitAnimations];
}
}
@end