我遇到了这种奇怪的情况,我有几个UIViews。当用户点击其中一个时,它们都是动画的(基本上改变了它们的Y轴位置)。现在,当我点击之后的任何视图并获得superview的所有子视图时,添加了2个UIImageViews。我在应用程序中根本没有图像,也没有创建任何图像。以下是所有子视图的日志:
首先点击:
2012-10-12 08:53:00.579 KIP_Acordion[1094:11603] <UIView: 0x71b96d0; frame = (5 5; 733 40); tag = 1; layer = <CALayer: 0x71b9730>>
2012-10-12 08:53:00.582 KIP_Acordion[1094:11603] <UIView: 0x71c2160; frame = (5 55; 733 40); tag = 2; layer = <CALayer: 0x71c20e0>>
2012-10-12 08:53:00.582 KIP_Acordion[1094:11603] <UIView: 0x71c4920; frame = (5 105; 733 40); tag = 3; layer = <CALayer: 0x71c49e0>>
2012-10-12 08:53:00.583 KIP_Acordion[1094:11603] <UIView: 0x71c6ed0; frame = (5 155; 733 40); tag = 4; layer = <CALayer: 0x71c6f90>>
2012-10-12 08:53:00.583 KIP_Acordion[1094:11603] <UIView: 0x71c93a0; frame = (5 205; 733 40); tag = 5; layer = <CALayer: 0x71c9320>>
2012-10-12 08:53:00.584 KIP_Acordion[1094:11603] <UIView: 0x71cb720; frame = (5 255; 733 40); tag = 6; layer = <CALayer: 0x71cb7e0>>
第二次点击:
KIP_Acordion[1094:11603] <UIView: 0x71b96d0; frame = (5 5; 733 40); tag = 1; layer = <CALayer: 0x71b9730>>
2012-10-12 08:55:52.937 KIP_Acordion[1094:11603] <UIView: 0x71c2160; frame = (5 145; 733 40); tag = 2; layer = <CALayer: 0x71c20e0>>
2012-10-12 08:55:52.938 KIP_Acordion[1094:11603] <UIView: 0x71c4920; frame = (5 195; 733 40); tag = 3; layer = <CALayer: 0x71c49e0>>
2012-10-12 08:55:52.938 KIP_Acordion[1094:11603] <UIView: 0x71c6ed0; frame = (5 245; 733 40); tag = 4; layer = <CALayer: 0x71c6f90>>
2012-10-12 08:55:52.939 KIP_Acordion[1094:11603] <UIView: 0x71c93a0; frame = (5 295; 733 40); tag = 5; layer = <CALayer: 0x71c9320>>
2012-10-12 08:55:52.940 KIP_Acordion[1094:11603] <UIView: 0x71cb720; frame = (5 345; 733 40); tag = 6; layer = <CALayer: 0x71cb7e0>>
2012-10-12 08:55:52.941 KIP_Acordion[1094:11603] <UIImageView: 0x755ef60; frame = (731 403; 7 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x755efc0>>
2012-10-12 08:55:52.941 KIP_Acordion[1094:11603] <UIImageView: 0x755f010; frame = (731 403; 7 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x755f0b0>>
导致这种情况的原因是什么?
编辑:一些其他信息:
每个UIView(称为父视图)都有两个子视图,一个是UIView(称之为标题栏)和一个UIScrollView,滚动视图的高度为0.1,当你点击标题栏时,滚动视图高度被重置并且动画如此它将显示它的子视图(现在是一系列UILabels和UITextfields)。然后根据正在显示的滚动视图的新高度重置所有其他父视图y位置,并将它们设置为新位置的动画。
我发现添加的UIImageViews在关闭打开的scrollview的方法上。
- (void) closeAndCleanSections : (UIView* ) tappedSection {
//get all the sections
NSArray* allSections = [[tappedSection superview]subviews];
//loop through all the sections
for(int s=0; s<allSections.count; s++) {
if([[allSections objectAtIndex:s] isKindOfClass:[UIView class]]) {
NSLog(@"%@", [allSections objectAtIndex:s]);
}
}//loop through sections
}
这是我用来为视图设置动画的方法:
- (void) openSection : (UIView* ) sectionToOpen {
//get the scroll view (the hidden part)
NSArray* sectionViews = [sectionToOpen subviews];
UIScrollView* contentWrapper = [sectionViews objectAtIndex:1];
//get all the sections
NSArray* allSections = [[sectionToOpen superview] subviews];
//determine which section was tapped
int thisSectionID = sectionToOpen.tag;
NSString* storedID = [NSString stringWithFormat:@"Section_%i", thisSectionID];
//get it's opened and closed height
NSDictionary* thisSectionDictionary = [sections objectForKey:storedID];
float thisSectionOpenedHeight = [[thisSectionDictionary objectForKey:@"Section Opened Height"] floatValue];
float thisSectionClosedHeight = [[thisSectionDictionary objectForKey:@"Section Closed Height"] floatValue];
//adjust the parent scroll
CGRect svParentFrame = self.frame;
//take away the section's closed height
svParentFrame.size.height = svParentFrame.size.height - thisSectionClosedHeight;
//replace with the opened height (add 50.0 for padding)
svParentFrame.size.height = svParentFrame.size.height + thisSectionOpenedHeight + 50.0;
self.frame = svParentFrame;
//adjust the content wrapper's height
CGRect contentWrapperFrame = contentWrapper.frame;
contentWrapperFrame.size.height = thisSectionOpenedHeight;
//determine where all the sections need to be moved too
if (thisSectionID == 1) {
for(int s=0; s<allSections.count; s++) {
if (s>0) {
UIView* thisSection = [allSections objectAtIndex:s];
CGRect thisSectionFrame = thisSection.frame;
thisSectionFrame.origin.y = thisSectionFrame.origin.y + thisSectionOpenedHeight + 10.0;
//animate the view
[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionCurveEaseOut
animations:^{
thisSection.frame = thisSectionFrame;
}
completion:^ (BOOL finished) {
}
];
}
}
} else {
float yDifference;
float currentY;
//move sections
for(int s=0; s<allSections.count; s++) {
//get the section
UIView* thisSection = [allSections objectAtIndex:s];
//get its frame
CGRect thisSectionFrame = thisSection.frame;
if (s+1 == thisSectionID) {
//current y location
currentY = thisSectionFrame.origin.y;
yDifference = (currentY - 10.0);
float newYLocation = 10.0;
thisSectionFrame.origin.y = newYLocation;
} else if (s+1 < thisSectionID) {
//set new y
float newYLocation = (s+1) * -80;
thisSectionFrame.origin.y = newYLocation;
} else {
float newYLocation = (thisSectionFrame.origin.y + thisSectionOpenedHeight) - (currentY - 20.0);
thisSectionFrame.origin.y = newYLocation;
}
//animate the sections
[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionCurveEaseOut
animations:^{
thisSection.frame = thisSectionFrame;
}
completion:^ (BOOL finished) {
}
];
}
}
//animate the section scroll view
[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionCurveEaseOut
animations:^{
contentWrapper.frame = contentWrapperFrame;
}
completion:^ (BOOL finished) {
}
];
}