contentView 的动画高度约束将导致其子视图的其他不需要的动画

时间:2021-07-01 03:53:35

标签: ios swift animation

我正在使用 https://github.com/sberrevoets/SDCAlertView ,它支持对 #imported libraries train = ImageDataGenerator(rescale=1/255) test = ImageDataGenerator(rescale=1/255) train_dataset = train.flow_from_directory(r'C:\Users\mishr\OneDrive\Desktop\jj', target_size=(150,150), batch_size = 32, class_mode='categorical') test_dataset = test.flow_from_directory(r"C:\Users\mishr\Downloads\SoML_Hackathon\SoML-50\test_data", target_size=(150,150), batch_size =32, class_mode='categorical') model = Sequential([ Conv2D(16, (3, 3), activation='relu', input_shape=(150, 150, 3)), MaxPooling2D(2, 2), Conv2D(32, (3, 3), activation='relu'), MaxPooling2D(2, 2), Conv2D(64, (3, 3), activation='relu'), Conv2D(64, (3, 3), activation='relu'), MaxPooling2D(2, 2), Flatten(), Dense(512, activation='relu'), #Dense(512, activation='relu'), Dense(3, activation='softmax') ]) model.summary() model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy']) model.fit_generator(train_dataset, steps_per_epoch = 250, epochs = 10, validation_data = test_dataset ) def predictImage(filename): img1 = image.load_img(filename,target_size=(150,150)) plt.imshow(img1) Y = image.img_to_array(img1) X = np.expand_dims(Y,axis=0) val = model.predict(X) print(val) 喜欢的演示文稿的自定义视图。

  1. UIAlertController 是一个 PresetColorView。它包含一个 UIView
  2. UICollectionView 被添加为 PresetColorView
  3. 的子视图
  4. 我们更改了 alertAlertController.contentView
  5. 我们在 alertAlertController.contentView.heightAnchor.constraint 块内对 alertAlertController.view.layoutIfNeeded() 执行调用。请注意,UIView.animatealertAlertController.view 的父视图。

动画代码看起来很简单

alertAlertController.contentView

enter image description here

正如您在动画中看到的,这也会导致 private func animateHeight(_ pageIndex: Int) { guard let heightConstraint = self.heightConstraint else { return } guard let alertAlertController = self.alertAlertController else { return } let contentView = alertAlertController.contentView let height = getHeight(pageIndex, contentView) alertAlertController.view.layoutIfNeeded() // height constraint for alertAlertController.contentView heightConstraint.constant = height UIView.animate(withDuration: 2) { // // Not alertAlertController.contentView.layoutIfNeeded() // We need to perform layoutIfNeeded on parent view. // alertAlertController.view.layoutIfNeeded() } } 上的“淡入”/“淡出”动画。

我可以知道为什么会这样吗?

我已经尝试过 Prevent unwanted animations on subviews when animating constraints 的建议,但没有用。这是我做过的两件事

  1. UICollectionView中使用UIView.performWithoutAnimation
  2. layoutSubviews中使用UIView.performWithoutAnimation

我可以知道为什么 contentView 的动画高度约束会导致其子视图的其他不需要的动画吗?

源代码

cellForItemAt

0 个答案:

没有答案