내 앱용 UITableViewCell을 사용자 정의하고 있는데 여러 번 해봤 기 때문에 모든 것이 잘됩니다.사용자 정의 셀을 사용하여 일부 속성을 변경할 수 없습니다.
이제 애니메이션을 몇 개 만들고 문제를 해결하려고합니다.
나는 가능한 한 짧은 설명 할 것이다 : 내가 사전 응용 프로그램을하고 있어요
. 내 사용자 지정 셀 (NTNHistoryCell) 함께 UITableView 포함하는보기가,이보기는 사용자의 연구 기록을 표시하기위한 것입니다.
#import <UIKit/UIKit.h>
#import "HistoryItem.h"
@protocol NTNHistoryCellDelegate;
@interface NTNHistoryCell : UITableViewCell<UIGestureRecognizerDelegate>
@property (strong, nonatomic) HistoryItem *historyItem;
@property (strong, nonatomic) IBOutlet UILabel *lblWord;
@property (strong, nonatomic) IBOutlet UILabel *lblDictName;
@property (strong, nonatomic) IBOutlet UILabel *lblTimeStamp;
//variables for editing
@property (strong, nonatomic) IBOutlet UIImageView *imgDeleteBackground;
@property (strong, nonatomic) IBOutlet UIView *frontView;
@property (strong, nonatomic) UIImageView *imgIconDelete;
@property (strong, nonatomic) id<NTNHistoryCellDelegate> delegate;
-(void)initLabels;
@end
@protocol NTNHistoryCellDelegate <NSObject>
@optional
-(void)historyCellIsDeleted:(NTNHistoryCell*)historyCell;
@end
사용자는 왼쪽 또는 항목을 삭제 오른쪽으로 스 와이프 할 수 있습니다. 셀에 중요한 두 가지 사항이 있습니다. 사용자가 스 와이프하는 동안 색상을 변경하는 UIImageView와 같은 배경, UILabels이 포함 된 UIView로 frontView, 사용자가 스 와이프하는 동안 frontView가 프레임을 변경합니다. 사용자가 번역본을 스 와이프하면 셀이 삭제됩니다 (해당 항목은 데이터베이스에서도 삭제됩니다).
이제 테이블 뷰가로드 될 때마다 셀을 스 와이프 할 수 있음을 알리는 애니메이션을 만들고 싶습니다. 나는 아래의 코드로 이벤트 didEndDisplayingCell을 사용 : 그것은 모든 코드와 잘려고하고 있지 않다
-(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
//do cell animation to inform user that the cell can be swiped to delete
//only for the 1st row
if(indexPath.row == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row)
{
NTNHistoryCell *cell = (NTNHistoryCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
CGRect originalFrame = cell.frontView.frame;
[UIView beginAnimations:@"move" context:nil];
[UIView setAnimationDuration:1.0];
//move left
//not working!
cell.frontView.frame = CGRectMake(-originalFrame.size.width, originalFrame.origin.y, originalFrame.size.width, originalFrame.size.height);
cell.lblWord.text = @"text change test";//not working!
cell.lblDictName.text = @"text change test";//not working!
cell.frontView.backgroundColor = [UIColor greenColor];//work fine!
[UIView commitAnimations];
}
}
, 당신은 내가 배경색하지만 UILabel의 텍스트 및 FrontView에의 프레임을 변경할 수 있습니다, 내 댓글을 볼 수 있습니다.
왼쪽으로 이동 한 다음 frontView를 오른쪽으로 이동하려고합니다.
어디서 잘못 되었나요? http://i.stack.imgur.com/dUddJ.png
편집 : 내가 그것을 해결 여기
은 내 말을 명확하게하기 위해 스크린 샷 (I 이미지를 게시하기에 충분한 평판을 가지고하지 않은 경우)입니다. @danypata 답장에 대한 내 의견보기.
자동 레이아웃을 사용하고 있습니까? – danypata
@danypata 아니, 나는 모든 xib를 위해 그것을 끈다! –
이렇게하면 직선이됩니다. 셀이 표시 될 때마다 테이블보기에서 첫 번째 보이는 셀에 애니메이션을 적용하겠습니까? – danypata